开发者

Change default find method in rails

开发者 https://www.devze.com 2023-01-06 08:55 出处:网络
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 th

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
0

精彩评论

暂无评论...
验证码 换一张
取 消