如何跟踪Rails中路由命中的控制器?

时间:2013-02-25 18:18:44

标签: ruby-on-rails

我有一个网址:http://api.mysite.com/api/v3/publishers/somepublisher.json?callback=mysite.publisherLoaded,我正在尝试跟踪调用哪个方法来访问该网址。响应是包含在publisherLoaded回调中的JSON字符串。

有人可以指导我如何开始跟踪此事吗?

我的routes.rb相当大,所以我粘贴了相关的细分:

API_OPTIONS = {:requirements => {:api_version => /v(1|2|3)/}} unless Object.const_defined?(:API_OPTIONS)

ActionController::Routing::Routes.draw do |map|

  map.namespace :api, API_OPTIONS.merge(:path_prefix => '/api/:api_version') do |api|
    api.resources :apps, :member => {:authenticate => :get}
    api.resources :foreign_currencies
    api.resources :designers

    api.resources :publishers, API_OPTIONS.merge(:has_many => [:user_sessions, :products], :member => {:login => :get, :authenticate => :get}) do |publisher|
      publisher.resources :app_earning_constraints
      publisher.resource :charts, API_OPTIONS
      publisher.resource :reports, API_OPTIONS
      publisher.resources :rules, API_OPTIONS      
      publisher.resources :sales, API_OPTIONS.merge(
        :collection => { :current => :get }
      )

    # Generic App Scoped Services
    map.namespace :api, API_OPTIONS.merge(:path_prefix => '/api/:api_version/app/:app_id', :name_prefix => 'api_app_') do |api|
      api.resources :publishers, API_OPTIONS.merge(:has_many => [:aisles], :member => {:login => :get}) do |publisher|
        publisher.resources :users, API_OPTIONS.merge(:member => {:authenticate => :post}) do |user|
          user.resource :app_state, API_OPTIONS.merge(:controller => 'user_app_states')

          # Used to generate a session from OAuth data (OpenSocial integrations)
          user.resources :sessions, API_OPTIONS

        end            

        publisher.resources :application_events, 
          :as => 'events',
          :only => :none, 
          :collection => { :install => :post, :uninstall => :post }

        publisher.resources :credit_transfer_pricepoints, API_OPTIONS
      end
    end
  end

  # Dynamic javascripts
  map.connect 'javascripts/*javascript.plain.js', :controller => 'javascripts', :action => 'show', :format => 'js', :requirements => {:javascript => /#{Dir['app/views/javascripts/**/*.js.erb'].map {|s| s[22..-8]} * '|'}/}
  map.connect 'javascripts/*javascript.js', :controller => 'javascripts', :action => 'show', :format => 'js', :requirements => {:javascript => /#{Dir['app/views/javascripts/**/*.js.erb'].map {|s| s[22..-8]} * '|'}/}


  # Administration Site
  map.with_options(:controller => 'admin/site') do |admin_site|
    admin_site.admin_default 'admin', :action => 'index'
    admin_site.admin_home 'admin/home', :action => 'index'
  end


  map.notfound '*url', :controller => 'error', :action => 'notfound'
end

1 个答案:

答案 0 :(得分:0)

按照adamdunson的建议运行bundle exec rake routes后,我发现我想要的是:

GET /api/:api_version/publishers/:id(.:format) {:controller=>"api/publishers", :action=>"show"}

它使用publishers文件夹中的api控制器。