Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Alternative Default Routes (See related posts)

I prefer :controller/:id/:action formatted URIs to :controller/:action/:id. For instance, "people/56/edit" to "people/edit/56". This is a simple matter of taste and has no real benefits other than being a bit more intuitive to certain brains.

It's also a bit harder to do than you might expect. You need to replace the default :controller/:action/:id route with the following:

map.connect ':controller/:action', 
            :requirements => { :action => /\D+/ }

map.connect ':controller/:id/:action',
            :action => 'show',
            :requirements => { :id => /\d+/ }


This will result in the following URIs for the basic set of CRUD actions generated by default:

/people/         (:action => 'index')
/people/new
/people/create
/people/56/      (:action => 'show' by default)
/people/56/edit
/people/56/remove
/people/56/update


You could argue that the default route setup in Rails is a correct default because it's a bit more simple to apply across all cases.

You need to create an account or log in to post comments to this site.


Click here to browse all 5143 code snippets

Related Posts