Skip to content

Instantly share code, notes, and snippets.

@roushkaman
roushkaman / gist:4278259
Created December 13, 2012 17:50
Есть парочка проблем и вопросов: 1.не могу заставить работать как хелпер 2.как делать исключение? 3.и где установить limit, так как везде он получаеться не определенным методом?
def self.similar(current_product)
semilars = self.where(:part_id => current_product.part_id, :model_id => current_product.model_id)
if semilars.count < 5
semilars |= self.where(:model_id => current_product.model_id)
if semilars.count < 5
sem = semilars | self.all
else
semilars
end
end
@roushkaman
roushkaman / gist:4369321
Last active December 10, 2015 02:39
добавляю я значит такую строчку в контроллер Prodects, collection, или фильтр after делаю, при выполнении ошибка: AbstractController::DoubleRenderError in ProductsController#index
redirect_to product_path(@search.first) if @search.count == 1
#AbstractController::DoubleRenderError in ProductsController#index
#Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return".
# -*- encoding : utf-8 -*-
class ProductsController < InheritedResources::Base
actions :show, :index
before_filter LocationGonFilter, :only => [:show]
def show
show! { @silimiar_products = ProductDecorator.decorate(Product.similar(@product.car_and_part_name)) }
end
def index
context :search do
before { get :index, :search => { :full_search => product.name } }
context :with_one_product do
it do
get :show, :id => product.id
response.should be_success
end
end
class ProductsController < InheritedResources::Base
actions :show, :index
before_filter LocationGonFilter, :only => [:show]
def show
show! do
@silimiar_products = ProductDecorator.decorate(Product.similar(@product)) } #как это метод после объявления приминять?
end
end