Commit da86792c by Tran Hoang Viet

VietTH: Fix review and feedback code

parent a29c7bbd
...@@ -27,7 +27,7 @@ gem 'sdoc', '~> 0.4.0', group: :doc ...@@ -27,7 +27,7 @@ gem 'sdoc', '~> 0.4.0', group: :doc
# gem 'bcrypt', '~> 3.1.7' # gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server # Use Unicorn as the app server
# gem 'unicorn' gem 'unicorn'
# Use Capistrano for deployment # Use Capistrano for deployment
# gem 'capistrano-rails', group: :development # gem 'capistrano-rails', group: :development
...@@ -55,5 +55,8 @@ gem 'quiet_assets' ...@@ -55,5 +55,8 @@ gem 'quiet_assets'
gem 'vacuum', '~> 1.3.0' gem 'vacuum', '~> 1.3.0'
gem 'figaro', '~> 1.1.1' gem 'figaro', '~> 1.1.1'
gem 'settingslogic', '~> 2.0.9'
gem 'draper', '~> 2.1.0' gem 'draper', '~> 2.1.0'
\ No newline at end of file
gem 'devise', '~> 3.5.1'
\ No newline at end of file
...@@ -37,6 +37,7 @@ GEM ...@@ -37,6 +37,7 @@ GEM
thread_safe (~> 0.3, >= 0.3.4) thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1) tzinfo (~> 1.1)
arel (6.0.0) arel (6.0.0)
bcrypt (3.1.10)
binding_of_caller (0.7.2) binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1) debug_inspector (>= 0.0.1)
builder (3.2.2) builder (3.2.2)
...@@ -52,6 +53,13 @@ GEM ...@@ -52,6 +53,13 @@ GEM
coffee-script-source (1.9.1.1) coffee-script-source (1.9.1.1)
columnize (0.9.0) columnize (0.9.0)
debug_inspector (0.0.2) debug_inspector (0.0.2)
devise (3.5.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 3.2.6, < 5)
responders
thread_safe (~> 0.1)
warden (~> 1.2.3)
draper (2.1.0) draper (2.1.0)
actionpack (>= 3.0) actionpack (>= 3.0)
activemodel (>= 3.0) activemodel (>= 3.0)
...@@ -90,6 +98,7 @@ GEM ...@@ -90,6 +98,7 @@ GEM
railties (>= 4.2.0) railties (>= 4.2.0)
thor (>= 0.14, < 2.0) thor (>= 0.14, < 2.0)
json (1.8.3) json (1.8.3)
kgio (2.9.3)
loofah (2.0.2) loofah (2.0.2)
nokogiri (>= 1.5.9) nokogiri (>= 1.5.9)
mail (2.6.3) mail (2.6.3)
...@@ -103,6 +112,7 @@ GEM ...@@ -103,6 +112,7 @@ GEM
mysql2 (0.3.18) mysql2 (0.3.18)
nokogiri (1.6.6.2) nokogiri (1.6.6.2)
mini_portile (~> 0.6.0) mini_portile (~> 0.6.0)
orm_adapter (0.5.0)
pry (0.10.1) pry (0.10.1)
coderay (~> 1.1.0) coderay (~> 1.1.0)
method_source (~> 0.8.1) method_source (~> 0.8.1)
...@@ -138,10 +148,13 @@ GEM ...@@ -138,10 +148,13 @@ GEM
activesupport (= 4.2.3) activesupport (= 4.2.3)
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
raindrops (0.14.0)
rake (10.4.2) rake (10.4.2)
rdoc (4.2.0) rdoc (4.2.0)
json (~> 1.4) json (~> 1.4)
request_store (1.1.0) request_store (1.1.0)
responders (2.1.0)
railties (>= 4.2.0, < 5)
ruby_parser (3.7.0) ruby_parser (3.7.0)
sexp_processor (~> 4.1) sexp_processor (~> 4.1)
sass (3.4.15) sass (3.4.15)
...@@ -154,6 +167,7 @@ GEM ...@@ -154,6 +167,7 @@ GEM
sdoc (0.4.1) sdoc (0.4.1)
json (~> 1.7, >= 1.7.7) json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0) rdoc (~> 4.0)
settingslogic (2.0.9)
sexp_processor (4.6.0) sexp_processor (4.6.0)
slop (3.6.0) slop (3.6.0)
spring (1.3.6) spring (1.3.6)
...@@ -178,9 +192,15 @@ GEM ...@@ -178,9 +192,15 @@ GEM
uglifier (2.7.1) uglifier (2.7.1)
execjs (>= 0.3.0) execjs (>= 0.3.0)
json (>= 1.8.0) json (>= 1.8.0)
unicorn (4.9.0)
kgio (~> 2.6)
rack
raindrops (~> 0.7)
vacuum (1.3.0) vacuum (1.3.0)
jeff (~> 1.0) jeff (~> 1.0)
multi_xml (~> 0.5.0) multi_xml (~> 0.5.0)
warden (1.2.3)
rack (>= 1.0)
web-console (2.1.3) web-console (2.1.3)
activemodel (>= 4.0) activemodel (>= 4.0)
binding_of_caller (>= 0.7.2) binding_of_caller (>= 0.7.2)
...@@ -193,6 +213,7 @@ PLATFORMS ...@@ -193,6 +213,7 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
byebug byebug
coffee-rails (~> 4.1.0) coffee-rails (~> 4.1.0)
devise (~> 3.5.1)
draper (~> 2.1.0) draper (~> 2.1.0)
figaro (~> 1.1.1) figaro (~> 1.1.1)
font-awesome-sass font-awesome-sass
...@@ -205,10 +226,12 @@ DEPENDENCIES ...@@ -205,10 +226,12 @@ DEPENDENCIES
rails (= 4.2.3) rails (= 4.2.3)
sass-rails (~> 5.0) sass-rails (~> 5.0)
sdoc (~> 0.4.0) sdoc (~> 0.4.0)
settingslogic (~> 2.0.9)
spring spring
turbolinks turbolinks
twitter-bootstrap-rails (~> 3.2.0) twitter-bootstrap-rails (~> 3.2.0)
uglifier (>= 1.3.0) uglifier (>= 1.3.0)
unicorn
vacuum (~> 1.3.0) vacuum (~> 1.3.0)
web-console (~> 2.0) web-console (~> 2.0)
......
class HomeController < ApplicationController class HomeController < ApplicationController
def index def index
@categories = Category.limit(LIMIT_CATEGORY).select(Category::JSON_DEFAULT) @categories = Category.limit(Settings.limit_category).select(Category::JSON_DEFAULT)
@recommended_items = Product.recommended @recommended_items = Product.recommended
@newest_items = Product.newest @newest_items = Product.newest
......
class Product < ActiveRecord::Base class Product < ActiveRecord::Base
scope :recommended, ->{ self.offset(rand(self.count)).limit(LIMIT_PRODUCT_RECOMMENDED) } # scopes
scope :newest, ->{ self.order(created_at: :desc).limit(LIMIT_PRODUCT_NEWEST) } scope :recommended, ->{ self.offset(rand(self.count)).limit(Settings.limit_product_recommended) }
scope :newest, ->{ self.order(created_at: :desc).limit(Settings.limit_product_newest) }
# relations
belongs_to :category belongs_to :category
belongs_to :user belongs_to :user
# validates
validates :title, presence: true, length: {maximum: 255}
validates :category, presence: true
enum product_type: %i(system amazon) enum product_type: %i(system amazon)
end end
class Settings < Settingslogic
source "#{Rails.root}/config/settings.yml"
namespace Rails.env
suppress_errors Rails.env.production?
end
\ No newline at end of file
%li %li
= link_to category.decorate.title, category_path(category) = link_to category.decorate.title, category
\ No newline at end of file \ No newline at end of file
- items.each do |product| - products.each do |product|
.product-item.col-md-4.text-center .product-item.col-md-4.text-center
.product-title .product-title
= link_to product.title, product_path(product) = link_to product.title, product
.product-image.img-thumbnail .product-image.img-thumbnail
%img{src: product.image_md_url} = image_tag(product.image_md_url)
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
%h3.title Recommended Items %h3.title Recommended Items
.module .module
#recommend-items #recommend-items
= render '/categories/recommended', items: @recommended_items = render 'categories/recommended', products: @recommended_items
.clearfix .clearfix
...@@ -10,4 +10,4 @@ ...@@ -10,4 +10,4 @@
%h3.title Newest Items %h3.title Newest Items
.module .module
#newest-items.products-list-detail #newest-items.products-list-detail
= render '/categories/newest', items: @newest_items = render 'categories/newest', products: @newest_items
\ No newline at end of file \ No newline at end of file
%ul.breadcrumb
%li
%a{href: '#'}
Home
%li
%a{href: '#'}
Cate 1
\ No newline at end of file
...@@ -11,16 +11,17 @@ ...@@ -11,16 +11,17 @@
= render '/layouts/header' = render '/layouts/header'
#wrapper.container-fluid #wrapper.container-fluid
.row .row
.col-md-6.search-wrapper .col-md-6.search-wrapper
= render '/layouts/search' = render 'layouts/search'
.row .row
.col-md-12 .col-md-12
= render 'layouts/breadscrum' = render 'layouts/breadcrumb'
#content.row #content.row
.col-md-2.sidebar .col-md-2.sidebar
= render '/layouts/sidebar' = render 'layouts/sidebar'
.col-md-10 .col-md-10
= yield = yield
......
...@@ -38,4 +38,6 @@ Rails.application.configure do ...@@ -38,4 +38,6 @@ Rails.application.configure do
# Raises error for missing translations # Raises error for missing translations
# config.action_view.raise_on_missing_translations = true # config.action_view.raise_on_missing_translations = true
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
end end
LIMIT_CATEGORY = 5
LIMIT_PRODUCT_RECOMMENDED = 6
LIMIT_PRODUCT_NEWEST = 4
Rails.application.routes.draw do Rails.application.routes.draw do
devise_for :users
root 'home#index' root 'home#index'
resources :products resources :products
......
defaults: &defaults
limit_category: 5
limit_product_recommended: 6
limit_product_newest: 4
development:
<<: *defaults
test:
<<: *defaults
production:
<<: *defaults
\ No newline at end of file
class AddContraintsToProducts < ActiveRecord::Migration
def up
change_column :products, :title, :string, null: false
change_column :products, :category_id, :integer, index: true, null: false
end
def down
change_column :products, :title, :string
change_column :products, :category_id, :integer, index: true
end
end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150702054935) do ActiveRecord::Schema.define(version: 20150703024141) do
create_table "categories", force: :cascade do |t| create_table "categories", force: :cascade do |t|
t.datetime "created_at", null: false t.datetime "created_at", null: false
...@@ -25,15 +25,33 @@ ActiveRecord::Schema.define(version: 20150702054935) do ...@@ -25,15 +25,33 @@ ActiveRecord::Schema.define(version: 20150702054935) do
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.string "asin", limit: 255 t.string "asin", limit: 255
t.string "title", limit: 255 t.string "title", limit: 255, null: false
t.string "image_lg_url", limit: 255 t.string "image_lg_url", limit: 255
t.string "image_md_url", limit: 255 t.string "image_md_url", limit: 255
t.string "image_sm_url", limit: 255 t.string "image_sm_url", limit: 255
t.decimal "price", precision: 10 t.decimal "price", precision: 10
t.integer "category_id", limit: 4 t.integer "category_id", limit: 4, null: false
t.integer "product_type", limit: 4, default: 0 t.integer "product_type", limit: 4, default: 0
end end
add_index "products", ["category_id"], name: "index_products_on_category_id", using: :btree add_index "products", ["category_id"], name: "index_products_on_category_id", using: :btree
end create_table "users", force: :cascade do |t|
\ No newline at end of file t.string "email", limit: 255, default: "", null: false
t.string "encrypted_password", limit: 255, default: "", null: false
t.string "reset_password_token", limit: 255
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", limit: 4, default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip", limit: 255
t.string "last_sign_in_ip", limit: 255
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
end
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