在单选按钮选择上提交 Rails 表单
我有以下 rails 表单(有效),但我想删除 submit_tag 并在选择单选按钮后立即提交表单.我该怎么做?
I have the following rails form (which works) but I want to remove the submit_tag and have the form submit as soon as a radio button selection is made. How do I do that?
<% form_tag({ :controller => "votes", :action => "create", :id => @item.id } ) do %>
<p>
<% for i in 1..10 do %>
<%= radio_button_tag :rating, i %> <%=h i %>
<% end %>
</p>
<p>
<%= submit_tag "Create" %>
</p>
<% end %>
所以我找到了精确的解决方案(感谢输入人员,它帮助我重新定义了我的 Google 搜索).每个人都在正确的轨道上,但没有一个是正确的.
So I have found the precise solution (thanks for the input guys, it helped me redefine my Google searches). Everyone was on the right track, but none were spot on.
所需要做的就是将 'false, :onclick => "this.parentNode.submit();"' 添加到 radio_button_tag 表单助手中.false被选中与否,剩下的就一目了然了.
All that was needed was to add 'false, :onclick => "this.parentNode.submit();"' to the radio_button_tag form helper. The false is selected or not, and the rest is obvious.
现在正确的解决方案如下:
The correct solution now looks like:
<% form_tag({ :controller => "votes", :action => "create", :id => @item.id } ) do %>
<% for i in 1..10 do %>
<%= radio_button_tag :rating, i, false, :onclick => "this.parentNode.submit();" %> <%=h i %>
<% end %>
<% end %>