Customized Route Resource Helper URLs (to not use 'id')

Say I have a “Member” ActiveRecord object with a typical integer id
attribute, and a string ‘username’ attribute.

If I generate routes for members using map.resources :members, then the
output from the edit helper is:
edit_member_path(@member) => “members/23/edit”

My goal is that I really want:
edit_member_path(@member) => “members/billybob/edit”

Where instead of using .id it uses .username so that the links generated
by all of the different helper methods are prettier and memorable.

Is this possible via some kind of option? Can I simply replace these
helper methods with new implementations? I don’t even know where these
implementations are or what they really look like.

Thanks.

You need to change in routes.rb file for getting name instead of id…

Change what exactly? The resources method does not have options to
customize the behavior of the helper methods.

Seth,

This article may be helpful.

Anthony C.

Aha! That was even better than I hoped for. to_param is exactly what I
needed. Thanks

what useful it has

2010/4/13 Seth W. [email protected]