Commit d6fcc541 by vulehuan

daily commit code

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