Commit f6cdd883 by Truong Ba Dieu

Restruct space

parent 45697591
.navbar-brand{ .navbar-brand{
padding: 2px; padding: 2px;
img{ img{
height: 45px; height: 45px;
display: inline-block; display: inline-block;
margin-right: 10px; margin-right: 10px;
} }
} }
.logo{ .logo{
margin: 0; margin: 0;
line-height: 25px; line-height: 25px;
font-size: 22px; font-size: 22px;
font-family: serif; font-family: serif;
} }
.wrap-img{ .wrap-img{
display: inline-block; display: inline-block;
} }
#search-bar{ #search-bar{
margin: 20px 0; margin: 20px 0;
input[type="text"]{ input[type="text"]{
height: 35px; height: 35px;
} }
} }
\ No newline at end of file
.recommend{ .recommend{
} }
.products{ .products{
.wrap-img{ .wrap-img{
float: left; float: left;
} }
.title{ .title{
padding-left: 60px; padding-left: 60px;
} }
} }
\ No newline at end of file
.mar-top-20{ .mar-top-20{
margin-top: 20px; margin-top: 20px;
} }
.mar-bot-20{ .mar-bot-20{
margin-bottom: 20px; margin-bottom: 20px;
} }
.mar-r-10{ .mar-r-10{
margin-right: 10px; margin-right: 10px;
} }
.text-center{ .text-center{
text-align: center; text-align: center;
} }
.pad-0{ .pad-0{
padding: 0; padding: 0;
} }
\ No newline at end of file
...@@ -4,6 +4,6 @@ class ApplicationController < ActionController::Base ...@@ -4,6 +4,6 @@ class ApplicationController < ActionController::Base
protect_from_forgery with: :exception protect_from_forgery with: :exception
def get_categories def get_categories
@categories = Category.all @categories = Category.all
end end
end end
class CategoriesController < ApplicationController class CategoriesController < ApplicationController
before_filter :get_categories before_filter :get_categories
def show
@category = Category.find(params[:id]) def show
end @category = Category.find(params[:id])
end
end end
\ No newline at end of file
class HomeController < ApplicationController class HomeController < ApplicationController
add_breadcrumb "Home", :root_path add_breadcrumb "Home", :root_path
before_filter :get_categories before_filter :get_categories
before_filter :get_recommend before_filter :get_recommend
def index def index
params[:per_page] ||= 5 params[:per_page] ||= 5
params[:page] ||= 1 params[:page] ||= 1
@products = Product.page(params[:page]).per(params[:per_page]) @products = Product.page(params[:page]).per(params[:per_page])
end end
def search def search
add_breadcrumb "Search", :search_path add_breadcrumb "Search", :search_path
@products = Product.search(params) @products = Product.search(params)
end end
private private
def get_recommend def get_recommend
@recommend_products = Product.recommend @recommend_products = Product.recommend
end end
end end
\ No newline at end of file
class ProductsController < ApplicationController class ProductsController < ApplicationController
before_filter :get_categories before_filter :get_categories
def show def show
@product = Product.find(params[:id]) @product = Product.find(params[:id])
end end
end end
\ No newline at end of file
module ApplicationHelper module ApplicationHelper
def currency_number(price=0, currency="usd") def currency_number(price=0, currency="usd")
"#{currency}#{price}" "#{currency}#{price}"
end end
end end
class Category < ActiveRecord::Base class Category < ActiveRecord::Base
has_many :products has_many :products
end end
class Product < ActiveRecord::Base class Product < ActiveRecord::Base
belongs_to :category belongs_to :category
belongs_to :user belongs_to :user
dragonfly_accessor :image dragonfly_accessor :image
validates :pid, :title, :price, :category_id, presence: true validates :pid, :title, :price, :category_id, presence: true
validates :pid, uniqueness: true validates :pid, uniqueness: true
scope :recommend, -> {where(recommend: true)} scope :recommend, -> {where(recommend: true)}
def self.search(params) def self.search(params)
params[:per_page] ||= 5 params[:per_page] ||= 5
params[:page] ||= 1 params[:page] ||= 1
Product.order("release_date DESC").page(params[:page]).per(params[:per_page]) Product.order("release_date DESC").page(params[:page]).per(params[:per_page])
end end
end end
...@@ -2,7 +2,7 @@ class User < ActiveRecord::Base ...@@ -2,7 +2,7 @@ class User < ActiveRecord::Base
# Include default devise modules. Others available are: # Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable # :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable :recoverable, :rememberable, :trackable, :validatable
has_many :products has_many :products
end end
class DatetimeService class DatetimeService
def self.strptime(str = nil, type="%Y-%m-%d") def self.strptime(str = nil, type="%Y-%m-%d")
begin begin
DateTime.strptime(str, type) DateTime.strptime(str, type)
rescue rescue
DateTime.now DateTime.now
end end
end end
end end
\ No newline at end of file
- if @recommend_products.present? - if @recommend_products.present?
.row.recommends .row.recommends
- @recommend_products.each do |product| - @recommend_products.each do |product|
= render "products/recommend_item", product: product = render "products/recommend_item", product: product
- if @products.present? - if @products.present?
.products .products
- @products.each do |product| - @products.each do |product|
= render "products/item", product: product = render "products/item", product: product
.text-center .text-center
= paginate @products = paginate @products
\ No newline at end of file \ No newline at end of file
- if @products.present? - if @products.present?
.products .products
- @products.each do |product| - @products.each do |product|
= render "products/item", product: product = render "products/item", product: product
.text-center .text-center
= paginate @products = paginate @products
\ No newline at end of file \ No newline at end of file
...@@ -22,7 +22,7 @@ html ...@@ -22,7 +22,7 @@ html
= render_breadcrumbs :separator => ' / ' = render_breadcrumbs :separator => ' / '
.row.mar-top-20 .row.mar-top-20
.col-sm-4 .col-sm-4
= render 'shared/categories' = render 'shared/categories'
.col-sm-8 .col-sm-8
= yield = yield
.clearfix .clearfix
......
.row.mar-bot-20 .row.mar-bot-20
.col-lg-7 .col-lg-7
.wrap-img.mar-r-10 .wrap-img.mar-r-10
= image_tag product.image.thumb('51x32#').url = image_tag product.image.thumb('51x32#').url
.title= link_to product.title, product_path(product) .title= link_to product.title, product_path(product)
.col-lg-5 .col-lg-5
= "Price: #{currency_number(product.currency, product.price)}" = "Price: #{currency_number(product.currency, product.price)}"
.col-sm-4 .col-sm-4
h4= product.title h4= product.title
= image_tag product.image.thumb('71x38>') = image_tag product.image.thumb('71x38>')
\ No newline at end of file \ No newline at end of file
ul.list-group ul.list-group
- @categories.each do |cate| - @categories.each do |cate|
= link_to cate.name, category_path(cate), class: 'list-group-item' = link_to cate.name, category_path(cate), class: 'list-group-item'
\ No newline at end of file \ No newline at end of file
#search-bar #search-bar
= form_tag search_path, class: "form-horizontal", method: "GET" do |f| = form_tag search_path, class: "form-horizontal", method: "GET" do |f|
.row .row
.col-sm-9 .col-sm-9
= text_field_tag :keyword, params[:keyword], placeholder: "Keyword", class: "form-control" = text_field_tag :keyword, params[:keyword], placeholder: "Keyword", class: "form-control"
.col-sm-3 .col-sm-3
= submit_tag "Search", class: "btn btn-primary" = submit_tag "Search", class: "btn btn-primary"
p p
| Hello | Hello
= @resource.email = @resource.email
| ! | !
p p
......
namespace :crawler do namespace :crawler do
task :aws => :environment do task :aws => :environment do
# categories name want to craw # categories name want to craw
categories = %w(Books Music Electronics Software Kitchen) categories = %w(Books Music Electronics Software Kitchen)
categories.each do |search_cate| categories.each do |search_cate|
category = Category.find_or_create_by(name: search_cate) category = Category.find_or_create_by(name: search_cate)
(1..5).each do |page| (1..5).each do |page|
...@@ -13,7 +13,7 @@ namespace :crawler do ...@@ -13,7 +13,7 @@ namespace :crawler do
'SearchIndex' => search_cate, 'SearchIndex' => search_cate,
'ItemPage' => page, 'ItemPage' => page,
'ResponseGroup' => 'Medium' 'ResponseGroup' => 'Medium'
} }
}) })
items = VacuumAwsService.parse_items(response) items = VacuumAwsService.parse_items(response)
......
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