Commit add91609 by Vy Quoc Vu

make it better

parent 8714b293
...@@ -5,8 +5,10 @@ gem 'bootstrap-sass', '3.2.0.0' ...@@ -5,8 +5,10 @@ gem 'bootstrap-sass', '3.2.0.0'
gem 'will_paginate-bootstrap' gem 'will_paginate-bootstrap'
gem 'bootstrap-will_paginate', '0.0.10' gem 'bootstrap-will_paginate', '0.0.10'
gem 'faker', '1.4.2' gem 'faker', '1.4.2'
gem 'carrierwave', '0.10.0'
gem 'mini_magick', '3.8.0'
gem 'fog', '1.23.0'
gem 'puma', '2.11.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.3' gem 'rails', '4.2.3'
...@@ -56,3 +58,8 @@ group :test do ...@@ -56,3 +58,8 @@ group :test do
gem 'mini_backtrace', '0.1.3' gem 'mini_backtrace', '0.1.3'
gem 'guard-minitest', '2.3.1' gem 'guard-minitest', '2.3.1'
end end
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor', '0.0.2'
end
\ No newline at end of file
...@@ -52,11 +52,15 @@ class Admins::ProductsController < ApplicationController ...@@ -52,11 +52,15 @@ class Admins::ProductsController < ApplicationController
end end
def show def show
if params[:id].to_i > 0
if if
@product = Product.find(params[:id]) @product = Product.find(params[:id])
else else
flash[:danger] = "Only Admin" flash[:danger] = "Only Admin"
end end
else
redirect_to :action => :new
end
end end
private private
......
...@@ -7,4 +7,5 @@ class Admin < ActiveRecord::Base ...@@ -7,4 +7,5 @@ class Admin < ActiveRecord::Base
validates :email, presence: true, length: { maximum: 255 }, validates :email, presence: true, length: { maximum: 255 },
format: { with: VALID_EMAIL_REGEX }, format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false } uniqueness: { case_sensitive: false }
validates :name, presence: true, length: { maximum: 255 }
end end
class Cart < ActiveRecord::Base class Cart < ActiveRecord::Base
validates :name, presence: true, length: { maximum: 50 } validates :name, presence: true, length: { maximum: 255 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :mail, presence: true, length: { maximum: 255 }, validates :mail, presence: true, length: { maximum: 255 },
format: { with: VALID_EMAIL_REGEX } format: { with: VALID_EMAIL_REGEX }
belongs_to :user belongs_to :user
end end
class CartProduct < ActiveRecord::Base class CartProduct < ActiveRecord::Base
validates :name, presence: true, length: { maximum: 255 }
validates :price, presence: true, length: {maximum: 4} validates :price, presence: true, length: {maximum: 4}
end end
class Product < ActiveRecord::Base class Product < ActiveRecord::Base
belongs_to :category belongs_to :category
validates :name, presence: true, length: { maximum: 3000 } validates :name, presence: true, length: { maximum: 3000 }
validates :image, presence: true, length: { maximum: 1000 } validates :image, presence: true, length: { maximum: 1000 }
validates :description, presence: true, length: { maximum: 65000 } validates :description, presence: true, length: { maximum: 65000 }
......
...@@ -8,4 +8,6 @@ class User < ActiveRecord::Base ...@@ -8,4 +8,6 @@ class User < ActiveRecord::Base
validates :email, presence: true, length: { maximum: 255 }, validates :email, presence: true, length: { maximum: 255 },
format: { with: VALID_EMAIL_REGEX }, format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false } uniqueness: { case_sensitive: false }
validates :name, presence: true, length: { maximum: 255 }
end end
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<td><%= cart.name.to_s %></td> <td><%= cart.name.to_s %></td>
<td><%= number_to_currency(cart.total_price/100, :unit => "$")%></td> <td><%= number_to_currency(cart.total_price/100, :unit => "$")%></td>
<td><%= cart.address %></td> <td><%= cart.address %></td>
<%= form_for(cart, url: "/admins/carts/#{cart.id}/edit" ) do |f| %> <%= form_for(cart, url: "/admins/carts/#{cart.id}/edit" ,method: :get ) do |f| %>
<td><%= f.text_field :status, value: cart.status.to_s, size: 10 , class: "create_input" %> <td><%= f.text_field :status, value: cart.status.to_s, size: 10 , class: "create_input" %>
</td> </td>
<td> <td>
......
Rails.application.routes.draw do Rails.application.routes.draw do
get 'sessions/new' get 'sessions/new'
devise_for :users, controllers: { sessions: "users/sessions" } devise_for :admins, controllers:{ sessions: "admins/sessions"
devise_for :admins, controllers: { sessions: "admins/sessions" } }
devise_for :users, controllers:{ sessions: "users/sessions"
}
namespace :admins do namespace :admins do
resources :products, :carts, :users resources :products, :carts, :users
end end
...@@ -30,6 +32,7 @@ ...@@ -30,6 +32,7 @@
get 'carts/show' =>'carts#show' get 'carts/show' =>'carts#show'
post 'carts/create' => 'carts#create', as: 'create_cart' post 'carts/create' => 'carts#create', as: 'create_cart'
resources :users
resources :categories, only: [:index, :show] resources :categories, only: [:index, :show]
resources :products, only: [:index, :show] resources :products, only: [:index, :show]
resources :carts, only: [:info,:destroy] resources :carts, only: [:info,:destroy]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment