views:

135

answers:

2

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?

+1  A: 

Might want to read through section 3.8 on the routing guide but if I am correct (and as the guide suggests) it is the Ads controller.

Topher Fangio
The table in Section 3.8 directly below the example shows the different URL to controller mappings and there is one for "/magazines/1/ads/new" that points to "Ads" as the controller. I believe this is what you are asking.
Topher Fangio
To be a bit clearer: I believe "/magazines/1/ads/new" and "/magazines/1/ads/1/new" route to the same thing. You may just get to know what ad the user was on when they asked to create a new one with the second version.
Topher Fangio
Thanks. I didn't notice the controller mappings in the table.
Joe O'Driscoll
+1  A: 

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

Peter Wagenet