我正在尝试在 Rails 中提交表单而不刷新页面。我一直在网上四处寻找,但似乎添加 :remote => true 似乎并没有像我想象的那样改变我的形式。现在我每个问题都有多个答案,每个问题都连接到一个单选按钮,但我隐藏了单选按钮,因此单击标签本身会提交表单。单选按钮表单提交是否会刷新页面?我真的不确定,在这一点上会很感激任何帮助......
<%= form_for(uanswer, :remote => true) do |f| %>
<% answers.each_with_index do |answer, i| %>
<% unless answered_flag %>
<%= f.radio_button :answer_id, answer.id, :class => "radio hide",
:onclick => "this.form.submit();" %>
<% end %>
<%= f.label :answer_id, answer.answer, :class => "answer",
:value => answer.id %>
<% end %>
生成的 HTML 表单或多或少看起来像这样:
<form accept-charset="UTF-8" action="/uanswers" class="new_uanswer"
data-remote="true" id="new_uanswer" method="post"><div
style="margin:0;padding:0;display:inline"><input
name="utf8" type="hidden" value="✓"><input name="authenticity_token"
type="hidden" value="PY5ACVmrvDnt/iYF8RK6O7tDKAn2G2dFdLeBNZw5MJ4="></div>
</form>