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