简体   繁体   中英

How to track down the controller that a route in Rails is hitting?

I have a URL: http://api.mysite.com/api/v3/publishers/somepublisher.json?callback=mysite.publisherLoaded and I'm trying to track down which method is being called to access that. The response is a JSON string wrapped in the publisherLoaded callback.

Can anyone guide me on how to even start tracking this down?

My routes.rb is rather large, so I've pasted relevant segments:

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

After running bundle exec rake routes as suggested by adamdunson , I found that what I wanted was:

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

It was using the publishers controller in the api folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM