Commit add91609 by Vy Quoc Vu

make it better

parent 8714b293
......@@ -5,8 +5,10 @@ gem 'bootstrap-sass', '3.2.0.0'
gem 'will_paginate-bootstrap'
gem 'bootstrap-will_paginate', '0.0.10'
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'
gem 'rails', '4.2.3'
......@@ -55,4 +57,9 @@ group :test do
gem 'minitest-reporters', '1.0.5'
gem 'mini_backtrace', '0.1.3'
gem 'guard-minitest', '2.3.1'
end
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor', '0.0.2'
end
\ No newline at end of file
......@@ -52,10 +52,14 @@ class Admins::ProductsController < ApplicationController
end
def show
if
@product = Product.find(params[:id])
if params[:id].to_i > 0
if
@product = Product.find(params[:id])
else
flash[:danger] = "Only Admin"
end
else
flash[:danger] = "Only Admin"
redirect_to :action => :new
end
end
......
......@@ -7,4 +7,5 @@ class Admin < ActiveRecord::Base
validates :email, presence: true, length: { maximum: 255 },
format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
validates :name, presence: true, length: { maximum: 255 }
end
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
validates :mail, presence: true, length: { maximum: 255 },
format: { with: VALID_EMAIL_REGEX }
belongs_to :user
end
class CartProduct < ActiveRecord::Base
validates :name, presence: true, length: { maximum: 255 }
validates :price, presence: true, length: {maximum: 4}
end
class Product < ActiveRecord::Base
belongs_to :category
validates :name, presence: true, length: { maximum: 3000 }
validates :image, presence: true, length: { maximum: 1000 }
validates :description, presence: true, length: { maximum: 65000 }
......
......@@ -8,4 +8,6 @@ class User < ActiveRecord::Base
validates :email, presence: true, length: { maximum: 255 },
format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
validates :name, presence: true, length: { maximum: 255 }
end
......@@ -20,7 +20,7 @@
<td><%= cart.name.to_s %></td>
<td><%= number_to_currency(cart.total_price/100, :unit => "$")%></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>
<td>
......
Rails.application.routes.draw do
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
resources :products, :carts, :users
end
......@@ -30,6 +32,7 @@
get 'carts/show' =>'carts#show'
post 'carts/create' => 'carts#create', as: 'create_cart'
resources :users
resources :categories, only: [:index, :show]
resources :products, only: [:index, :show]
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