Commit d6fcc541 by vulehuan

daily commit code

parent 19f20f15
...@@ -4,8 +4,8 @@ ruby '2.0.0' ...@@ -4,8 +4,8 @@ ruby '2.0.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0' gem 'rails', '4.0.0'
# Use mysql as the database for Active Record gem 'mongoid', github: 'mongoid/mongoid'
gem 'mysql2' gem 'bson_ext'
# Use SCSS for stylesheets # Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0' gem 'sass-rails', '~> 4.0.0'
...@@ -45,12 +45,14 @@ gem 'bcrypt-ruby', '~> 3.0.0' ...@@ -45,12 +45,14 @@ gem 'bcrypt-ruby', '~> 3.0.0'
# Use debugger # Use debugger
# gem 'debugger', group: [:development, :test] # gem 'debugger', group: [:development, :test]
gem 'sunspot_rails', "~> 2.1.0" gem 'sunspot_rails', "~> 2.1.0"
gem 'sunspot_mongoid'
group :development, :test do group :development, :test do
gem 'sunspot_matchers' gem 'sunspot_matchers'
gem 'sunspot_solr', "~> 2.1.0" gem 'sunspot_solr', "~> 2.1.0"
gem 'rspec-rails', "~> 2.14.0" gem 'rspec-rails', "~> 2.14.0"
gem 'faker', '1.1.2' gem 'faker', '1.1.2'
gem 'binding_of_caller'
end end
group :development do group :development do
...@@ -64,7 +66,7 @@ group :test do ...@@ -64,7 +66,7 @@ group :test do
gem 'capybara', "~> 2.1.0" gem 'capybara', "~> 2.1.0"
gem 'factory_girl_rails' gem 'factory_girl_rails'
end end
gem 'will_paginate', '3.0.4' gem 'will_paginate_mongoid'
gem 'will_paginate-bootstrap', "~> 1.0.0" # gem 'will_paginate-bootstrap', "~> 1.0.0"
gem 'recaptcha-mailhide', "~> 0.1.1" gem 'recaptcha-mailhide', "~> 0.1.1"
gem "breadcrumbs_on_rails", "~> 2.3.0" gem "breadcrumbs_on_rails", "~> 2.3.0"
...@@ -7,12 +7,12 @@ class ProductsController < ApplicationController ...@@ -7,12 +7,12 @@ class ProductsController < ApplicationController
end end
def show def show
begin if Product.where(id: params[:id]).exists?
@product = Product.find(params[:id]) @product = Product.where(id: params[:id])
unless @product.status unless @product.status
user = current_user user = current_user
if user.blank? || @product.user_id != user.id if user.blank? || @product.user_id != user.id
redirect_to products_path redirect_to products_path and return
end end
end end
product_category = ProductCategory.find(@product.product_category_id) product_category = ProductCategory.find(@product.product_category_id)
...@@ -21,7 +21,7 @@ class ProductsController < ApplicationController ...@@ -21,7 +21,7 @@ class ProductsController < ApplicationController
add_breadcrumb @product.name, product_path(@product) add_breadcrumb @product.name, product_path(@product)
end end
@other_products = Product.get_other_products(@product.id, product_category_id: @product.product_category_id, limit: 20) @other_products = Product.get_other_products(@product.id, product_category_id: @product.product_category_id, limit: 20)
rescue else
flash[:error] = "Invalid product!" flash[:error] = "Invalid product!"
redirect_to products_path redirect_to products_path
end end
......
...@@ -66,10 +66,11 @@ class Product ...@@ -66,10 +66,11 @@ class Product
limit = options[:limit] limit = options[:limit]
product_category_id = options[:product_category_id] product_category_id = options[:product_category_id]
return Product.select('id, name, image_medium, price, price_currency') return Product.where(availability: 'instock')
.where(availability: 'instock').where(product_category_id: product_category_id).where('id != ?', product_id) .where(product_category_id: product_category_id)
.where(id: { $ne: product_id })
.where(status: true) .where(status: true)
.order('created_at DESC').order('updated_at DESC').order('name') .desc(:created_at).desc(:updated_at).asc(:name)
.limit(limit) .limit(limit)
end end
...@@ -77,11 +78,10 @@ class Product ...@@ -77,11 +78,10 @@ class Product
def self.get_list(options = { limit: 16 }) def self.get_list(options = { limit: 16 })
limit = options[:limit] limit = options[:limit]
page = options[:page] page = options[:page]
return Product.select('id, name, image_medium, price, price_currency') return Product.where(availability: 'instock')
.where(availability: 'instock')
.where(status: true) .where(status: true)
.desc(:created_at).desc(:updated_at).asc(:name)
.paginate(:page => page, :per_page => limit) .paginate(:page => page, :per_page => limit)
.order('created_at DESC').order('updated_at DESC').order('name')
end end
def self.get_user_items(options = { limit: 16, user_id: 0, all_status: false }) def self.get_user_items(options = { limit: 16, user_id: 0, all_status: false })
......
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