Ok, finally. This is the first post of a series about some new exciting edge rails features. ;)
Today I've found a commit that is actually a few days old but this will clean up a lot of my nested routes.
Imagine your application has a User who hasmany :posts which again hasmany :comments. Your routes would look something like:
map.resources :users do |user| user.resources :posts do |post| post.resources :comments end end
This defines the following helpers and URLs
users_url #=> /users/ user_posts_url #=> /users/1/posts/ user_post_comments_url #=> /users/1/posts/10/comments
however only the full nested routes are available. /posts/10 or /comments/10 are not available and you need to declare those seperately:
map.resources :posts do |post| post.resources :comments end map.resources :comments
This commit now allows you to add a :shallow => true option which does this automatically for you. This is great and shortens the routes.rb a lot. The example above would then just look like:
map.resources :users, :shallow => true do |user| user.resources :posts, :shallow => true do |post| post.resources :comments end end
and posturl, commenturl, postcommentsurl,... get also defined.
Have a look at the commit message and source code for more information.