简体   繁体   中英

How to interpolate handlebars values into a Rails link_to helper?

I'm working on a handlebars.erb template, but I'm getting an error when trying to put a handlebars {{id}} into a link_to helper. Any ideas how to do it?

<%= link_to "Link", edit_user_photo_path(id: {{id}} ) %>

This wont work, the value for the id will be {{id}}. If I put {{id}} outside the helper, its value is 139 . I don't know how can I make a link_to interpret the handlebars value!

Thanks

Since Handlebars is run on the client side of your page, it is unlikely that you will be able to use a value from Handlebars in a link that you are setting up with your Ruby code, which is evaluated by the server.

You shouldn't need Handlebars to make this link. Try to get the relevant id with your Ruby code.

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