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 som开发者_JAVA百科ething you added to the model? I think it was the latter?
Thanks in advance!
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.
- to_param API documentation
精彩评论