简体   繁体   中英

Can I use something other than id with link_to in my rails view?

The rails way of making links in your view is to use link_to . Passing it an object will link to that object's id . How can I use my object's match_id instead of id with link_to ?

您可以覆盖模型中的to_param方法以返回match_id的值以使link_to和其他rails助手在生成URL时自动使用该值。

If you're just using link_to(@object) I don't believe you can specify something other than the default object id. However, if you use the actual path helper for the route you want, you can specify the id with object_path(@object.match_id)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM