Search code examples
ruby-on-railscontrollernested-resources

With nested routes does the parent controller or the child controller process the request for the "new" action?


If you have a nested resource defined like this:

map.resources :magazines, :has_many => :ads.

for these models:

class Magazine < ActiveRecord::Base 
  has_many :ads 
end 

class Ad < ActiveRecord::Base 
  belongs_to :magazine 
end

When you invoke this url:

/magazines/1/ads/1/new 

with the nested route helper:

new_magazine_ad_path

Which controller handles this new action: the magazines controller or the ads controller?


Solution

  • You can use rake routes to see a list of all your routes including their names where applicable.