views:

22

answers:

1

I've read this somewhere but I can't find it now.

I'm trying to change the default "find" method on a model from the id to for example the name. So when I map resources to a model it uses the the name instead of the id.

I don't remember if this was a parameter in the resources command in the route file or if it was something you added to the model? I think it was the latter?

Thanks in advance!

+1  A: 

You're thinking of overriding the to_param method within the model so that a field other than the ID is used within URLs. This Railscast shows you how.

John Topley
i think he want User.find('salil') should return the user with name 'salil' instead of searching for id with 'salil'
Salil
Yeah, now I remember I didn't read it, I saw it in a Railscast ;) Thanks!
Alfred Nerstu