0

我有一条路线去:GET /api/:api_version/publishers/:id(.:format) {:controller=>"api/publishers", :action=>"show"}

所以我打开它publishers_controllerapi它看起来:

# Provides access to publisher information
class Api::PublishersController < Api::BaseResourceController
  inherit_resources
  respond_to_data_formats

  before_filter :find_publisher
  before_filter :require_publisher_login, :only => :authenticate

  actions :show

  # Note: We remove App scope from cache path, since Publisher info should be cached across all apps
  caches_action :show, :login, :cache_path => lambda {|c| {:version => c.send(:publisher_version), :model_version => Publisher.cache_config.version}}, :expires_in => 60.seconds

  # Action redirects the top frame to the publisher's site (for the user to log in)
  def login
    # Prevent infinite loop where the page redirects to itself.
    raise ArgumentError, 'Publisher website url is not configured' if @publisher.website_url.blank?
  end

  def authenticate 
    respond_with(@publisher)
  end

  private

    def find_publisher
      params[:publisher_id] = params[:id]
      super
    end

    def publisher_version
      @publisher.lock_version
    end

end

没有show功能,那我怎么看它的作用呢?

4

1 回答 1

2

这个类继承了show方法,大概来自Api::BaseResourceController. 如果我必须打赌,我猜它Api::BaseResourceController使用了inherited_resources或类似的东西,它只是假设该show方法应该做一件非常典型的事情:找到记录并使用可用的模板显示它。

于 2013-02-25T18:47:43.773 回答