Last active
December 10, 2015 05:39
-
-
Save roushkaman/4389451 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
def index | |
redirect_to(product_path(collection.first)) if collection.count == 1 | |
end | |
private | |
def collection | |
params[:search] ||= {} | |
params[:search][:full_search] ||= '' | |
@search ||= Product.search(params[:search]) | |
@hot_products = ProductDecorator.decorate(Product.latest_products) | |
@products ||= ProductDecorator.decorate @search.relation.default_order(seller_address).all | |
end | |
def resource | |
@product ||= ProductDecorator.decorate(super) | |
end | |
end | |
------------------------------------------------------------------------------------------------------- | |
#это говнокод, его покуда не оценивай | |
def similar(current_product) | |
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 | |
end | |
.limit(5 - res.count) # для начала лучше сделать res = [] ---------как это понять?? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ProductDecorator.decorate(resource).similar
- если в декоратор вставишь этот метод, то так вызывай его. Вместоcurrent_product
в декораторе можно обращаться кproduct
или кmodel
- это тот же объект