I need a little help from the Rails community.
Nested resources are a blessing. They give you so much for so little–understandable URLs, minimal configuration, logical routes. All in all it’s a blessing.
But it can be too restrictive.
For non-Railsies reading this (why?) or Railsies who haven’t gone all resourceful, here’s the deal. You define e.g. Artists and Videos in your web app. Artists have_many videos. Nested resources mean that the videos are defined inside the artists, like so:
map.resources :artists do |artist|
artist.resources :videos
end
This gives you URLs like so:
/artists/1/videos
to list all videos of artists 1. This works great. But in my app I would like to show the videos of all artists as well. I would like to have an URL like so:
/videos
which is to say, not bound by any particular artist.
This however does not seem possible. Once I define the second route, Rails complains about two routes with the same name. I have tried playing with name_prefix and other parameters, but have had no luck.
Does anyone know how to list both videos under a given artist, and global videos as well? I’d love to know.
Here is the answer you seek
http://weblog.jamisbuck.org/2007/2/5/nesting-resources
Ahh .. the immaculate Jamis does it again.
Thanks!