# Restful nested and unnested routes

**URL:** <https://www.ruby-forum.com/t/restful-nested-and-unnested-routes/106549>\
**Category:** Rails\
**Created:** [June 11, 2007, 9:06pm UTC](https://www.ruby-forum.com/t/restful-nested-and-unnested-routes/106549 "2007-06-11T21:06:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sebastian\_SchSSSSn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b38774/32.png) [@Sebastian\_SchSSSSn](https://www.ruby-forum.com/u/Sebastian_SchSSSSn)\
**Post date:** [June 11, 2007, 9:06pm UTC](https://www.ruby-forum.com/t/restful-nested-and-unnested-routes/106549/1 "2007-06-11T21:06:16Z")

</div>

Hi,

I´ve problems with the restful routes.

I know that /artists/1/songs works:

map.resources :artists do | artists |  
artists.resources :songs  
end

But how can I route to a list of all songs with artist, something  
like /songs … in a restful manner.

Thanks  
Sebastian

---

<div class="post-metadata">

**Author:** ![Sebastian\_SchSSSSn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b38774/32.png) [@Sebastian\_SchSSSSn](https://www.ruby-forum.com/u/Sebastian_SchSSSSn)\
**Post date:** [June 12, 2007, 7:21pm UTC](https://www.ruby-forum.com/t/restful-nested-and-unnested-routes/106549/2 "2007-06-12T19:21:42Z")

</div>

You could create a separate top-level song resource to accomplish  
this, e.g.,

map.resources :artists do |artist|  
artist.resources :songs, :name\_prefix =\> ‘artist\_’  
end  
map.resources :songs

This would create routes for a top-level song resource as well as your  
original nested song resource. The top-level song resource will have  
the usual route helpers. Because of the :name\_prefix option, the route  
helpers for the nested song resource will have “artist\_” prepended to  
their name to prevent them from conflicting with the top-level song  
resource, e.g., artist\_songs\_path(X) =\> /artists/X/songs.

-John
