[英]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. 我正在处理handlebars.erb模板,但是在尝试将把手
{{id}}
放入link_to帮助器时遇到错误。 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}}. 这将行不通,id的值为{{id}}。 If I put {{id}} outside the helper, its value is
139
. 如果我将{{id}}放在助手之外,则其值为
139
。 I don't know how can I make a link_to interpret the handlebars value! 我不知道如何制作一个link_来解释车把的值!
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. 由于Handlebars在页面的客户端上运行,因此不太可能在您使用Ruby代码设置的链接中使用Handlebars中的值,该链接由服务器评估。
You shouldn't need Handlebars to make this link. 您不需要把手来建立此链接。 Try to get the relevant id with your Ruby code.
尝试获取与您的Ruby代码相关的ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.