Suppose you have a user model, and you create some resourceful routes relating to that model. Normally rails uses the ID of a model for any parameters, such that ‘users/1’ would show a user with an ID of 1.
Turns out you can override which attribute is used. How? A
to_param method defined in the model. All you have to do is return the attribute you’d like to use instead, e.g. username.