rails/rails — pull request #5581 by jamie (2012-03-26 04:49:26+00:00)
Title: Allow a defining custom member field on resources

By default, resources routes are created with :resource/:id. A model
defining to_param can make prettier urls by using something more
readable than an integer ID when generating URLs, but since the route picks it up as :id you
wind up with awkward User.find_by_username(params[:id]) calls.

By overriding the key to be used in @request.params you can be more
obvious in your intent.

This override is basically as simple as it needs to be, just an extra :param
option on the resource(s) definition on the route. There's no work done to force
the url generators to use that field when passed a model, but since to_param
is already overridable I don't think it's necessary.

Patch includes tests for a plain resource as well as a nested resource
(generating user_login for the above example).