简体   繁体   中英

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

How can i have the id: with slug and the id as well. 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 ? instead of sub_category."#{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