views:

26

answers:

2

I'm looking at this code, I can see that is says actions: show and index but where are the methods show and index??

http://github.com/railsdog/spree/blob/master/core/app/controllers/products_controller.rb

class ProductsController < Spree::BaseController
  HTTP_REFERER_REGEXP = /^https?:\/\/[^\/]+\/t\/([a-z0-9\-\/]+\/)$/

  #prepend_before_filter :reject_unknown_object, :only => [:show]
  before_filter :load_data, :only => :show

  resource_controller
  helper :taxons
  actions :show, :index

  private

  def load_data
    load_object

    @variants = Variant.active.find_all_by_product_id(@product.id,
                :include => [:option_values, :images])
    @product_properties = ProductProperty.find_all_by_product_id(@product.id,
                          :include => [:property])
    @selected_variant = @variants.detect { |v| v.available? }

    referer = request.env['HTTP_REFERER']

    if referer  && referer.match(HTTP_REFERER_REGEXP)
      @taxon = Taxon.find_by_permalink($1)
    end
  end

  def collection
    @searcher = Spree::Config.searcher_class.new(params)
    @products = @searcher.retrieve_products
  end

  def accurate_title
    @product ? @product.name : nil
  end
end
+1  A: 

My guess is that the actions method is loaded with resource_controller as a module from the lib directory. Then calling the actions method creates the index and show methods.

John Drummond
I agree. I seems to be come from this plugin: http://github.com/jamesgolick/resource_controller
nathanvda
A: 

The class inherits from Spree::BaseController and ActionController. Spree::BaseController has method action which takes method names as messages.

Jagira