I've created patch which adds support for specifying a subset of named routes to create when mapping verb-oriented controllers for collections of resources (see http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/838).
You can specify which routes to add using :only and/or :except options with array values containing symbols of :collection, :new, :member and :associations.
This is especially useful for creating nested routes, so that the redundant parent ids are not required for routes containing explicit ids.
For example...
map.resources :posts do |post| post.resources :comments, :only => [ :collection, :new ] end map.resources :comments, :except => [ :collection, :new ]
The generated routes would nest the collection and new record routes for comment resources within posts...
e.g. GET /posts/1/comments or POST /posts/1/comments
However, the routes with explicit ids would not require the post_id...
e.g. GET /comments/2 instead of GET /posts/1/comments/2
This really helps to clean up urls when nesting resources more than once.
For example, instead of:
map.resources :projects do |project| project.resources :milestones do |milestone| milestone.resources :features do |feature| feature.resources :tasks end end end
You could use:
map.resources :projects do |project| project.resources :milestones, :only => [ :collection, :new ] end map.resources :milestones, :except => [ :collection, :new ] do | milestone> milestone.resources :features, :only => [ :collection, :new ] end map.resources :features, :except => [ :collection, :new ] do | feature> feature.resources :tasks, :only =>[ :collection, :new ] end map.resouces :tasks, :except => [ :collection, :new ]
This would result in the ability to simply access:
/features/72/tasks
Instead of:
/projects/13/milestones/16/features/72/tasks