Skip to content

Instantly share code, notes, and snippets.

@roushkaman
Created December 26, 2012 09:02
Show Gist options
  • Save roushkaman/4379020 to your computer and use it in GitHub Desktop.
Save roushkaman/4379020 to your computer and use it in GitHub Desktop.
# -*- 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
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])
@products ||= ProductDecorator.decorate @search.relation.default_order(seller_address).all
@hot_products = ProductDecorator.decorate(Product.latest_products)
end
def resource
@product ||= ProductDecorator.decorate(super)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment