简体   繁体   English

段和id与rails link_to的串联

[英]concatenatenation of slug and id with rails link_to

I have following link_to sub_category is a slug title(generated by friendly_id) stored in my db table 我有以下link_to sub_category是存储在我的数据库表中的子弹标题(由friendly_id生成)

How can i have the id: with slug and the id as well. 我怎么能拥有id:以及子弹和id I have tried something like this but it is a syntax error. 我已经尝试过类似的操作,但这是语法错误。

<%= link_to sub_category.name, controller: :posts, action: :product, id: sub_category."#{id}" %>

How can i solve it 我该如何解决

尝试这个 :

<%= link_to sub_category.name, controller: :posts, action: :product, id: sub_category.send("#{id}") %>

why not sub_category.id ? 为什么不sub_category.id instead of sub_category."#{id}" 而不是sub_category."#{id}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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