困惑,show和index动作的定义在哪里?

时间:2010-10-08 19:09:58

标签: ruby-on-rails

我正在看这段代码,我可以看到它是actions: show and index但是方法show和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

2 个答案:

答案 0 :(得分:1)

我的猜测是actions方法加载了resource_controller作为lib目录中的模块。然后调用actions方法创建索引并显示方法。

答案 1 :(得分:0)

该类继承自Spree :: BaseController和ActionController。 Spree :: BaseController有方法操作,它将方法名称作为消息。