Sha256: c31bfed43efd63e456e06f12498c9e2044f923407d63d8799153dd5f8e9d0750

Contents?: true

Size: 714 Bytes

Versions: 10

Compression:

Stored size: 714 Bytes

Contents

module Comable
  class ProductsController < Comable::ApplicationController
    before_filter :load_category_and_products, only: :index

    def index
      @products = @products.page(params[:page]).per(Comable::Config.products_per_page)
    end

    def show
      @product = Comable::Product.find(params[:id])
    end

    private

    def load_category_and_products
      @category = Comable::Category.where(id: params[:category_id]).first
      if @category
        subtree_of_category = Comable::Category.subtree_of(@category)
        @products = Comable::Product.eager_load(:categories).merge(subtree_of_category)
      else
        @products = Comable::Product.search(params[:q])
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
comable-frontend-0.6.0 app/controllers/comable/products_controller.rb
comable_frontend-0.5.0 app/controllers/comable/products_controller.rb
comable_frontend-0.4.2 app/controllers/comable/products_controller.rb
comable_frontend-0.4.1 app/controllers/comable/products_controller.rb
comable_frontend-0.4.0 app/controllers/comable/products_controller.rb
comable_frontend-0.3.4 app/controllers/comable/products_controller.rb
comable_frontend-0.3.3 app/controllers/comable/products_controller.rb
comable_frontend-0.3.2 app/controllers/comable/products_controller.rb
comable_frontend-0.3.1 app/controllers/comable/products_controller.rb
comable_frontend-0.3.0 app/controllers/comable/products_controller.rb