【发布时间】:2016-11-07 18:33:08
【问题描述】:
我有如下简单的 html.erb 表单
<table>
<%= text_field_tag :tesintg %>
<th><%= button_to 'Apply now', apply_product_index_path(:value => "Want Value of input in text field here") , method: :post %></th>
</table>
按下“立即应用”按钮时,我希望将测试 text_field_tag 中的值作为查询参数发布为 {"value" : "Value in the text field"}
我如何做到这一点。
【问题讨论】:
-
是否有某些原因您不能将这些元素包装在一个表单中并让它为您工作?那将是最简单的解决方案。否则,您将需要使用 JavaScript。
-
是的,使用传统的 html 表单更容易。或者,您可以使用 javascript 从文本字段中获取值并将其注入查询参数。
-
肖恩如何做到这一点。如何使用 javascript 获取值并在 button_to 行中使用它。
标签: html ruby-on-rails-4 erb