开发者

Change default find method in rails

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜