在单选按钮选择上提交 Rails 表单 [英] Submitting Rails Form on a Radio Button Selection

查看:44
本文介绍了在单选按钮选择上提交 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 %>&nbsp;<%=h i %>&nbsp;
    <% 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();" %>&nbsp;<%=h i %>&nbsp;
    <% end %>
<% end %>

这篇关于在单选按钮选择上提交 Rails 表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆