Over a million developers have joined DZone.

Alternative Default Routes

DZone's Guide to

Alternative Default Routes

· ·
Free Resource
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/56/      (:action => 'show' by default)

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.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}