(Copied from my stagnant SO post:
ruby on rails - Automatically add parent model id in nested resources - Stack Overflow.
Feel free to answer there and get reputation if you like.)
With nested resource routes in Rails 3, such as the following:
resources :magazines do
resources :ads
end
helpers such as magazine_ad_path
are defined, to which I have to
pass both a magazine and the ad, which is inconvenient if I just have
a reference to the ad:
magazine_ad_path(@ad.magazine, @ad)
Is there a nice way to set up an ad_path
helper that takes the @ad
and returns the appropriate address including the magazine ID? (This
would also then allow the use of link_to @ad
, redirect_to @ad
,
etc., which automatically call the ad_path
helper corresponding to
the model class.)