[英]Rails pass input in link_to
How can I pass html element input value in link_to path? 如何在link_to路径中传递html元素输入值?
%input#answer{type: "text", required: true}
%p
= link_to "Send", game_answer_path(@game), class: 'btn btn-default', remote: true
I can get my input value as document.getElementById("answer").value
, but how can I pass it in game_answer_path(@game, HERE )
? 我可以将输入值获取为document.getElementById("answer").value
,但是如何在game_answer_path(@game, HERE )
传递它呢?
How do you get value in the answer
field, if you get it from the backend then you can add to the link time when your view is being rendered so you can do something like, 您如何在answer
字段中获取价值,如果您是从后端获取的,那么可以在渲染视图时增加链接时间,这样您就可以执行以下操作:
= link_to "Send", game_answer_path(@game, :answer => @answer), class: 'btn btn-default', remote: true
if that value is being generated by a user action like user selecting or entering an answer then you need to use to dynamically append it to the value of the anchor (href) tag, using javascript you can do something like 如果该值是由用户操作(例如用户选择或输入答案)生成的,那么您需要使用javascript将其动态地附加到锚定(href)标记的值,您可以执行以下操作
var link = document.getElementById("link").value
document.getElementById("link").href = value + '/' + document.getElementById("answer").value
replace link
and answer
with respective id from your dom, if this is not what you are after, update your question. 将link
和answer
替换为来自您的dom的相应ID,如果这不是您想要的,请更新您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.