如何在link_to路径中传递html元素输入值?
%input#answer{type: "text", required: true}
%p
= link_to "Send", game_answer_path(@game), class: 'btn btn-default', remote: true
我可以将输入值设为document.getElementById("answer").value
,但如何在game_answer_path(@game, HERE )
中传递?
答案 0 :(得分:0)
如何在answer
字段中获得价值,如果从后端获取,那么您可以在渲染视图时添加链接时间,以便您可以执行类似的操作,
= link_to "Send", game_answer_path(@game, :answer => @answer), class: 'btn btn-default', remote: true
如果该值是由用户选择或输入答案等用户操作生成的,那么您需要使用它来动态地将其附加到anchor(href)标记的值,使用javascript可以执行类似
var link = document.getElementById("link").value
document.getElementById("link").href = value + '/' + document.getElementById("answer").value
将link
和answer
替换为dom中的相应ID,如果这不是您所追求的,请更新您的问题。