Submitting Rails Form on a Radio Button Selection

后端 未结 3 1471
梦毁少年i
梦毁少年i 2021-02-11 06:45

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?

<
3条回答
  •  礼貌的吻别
    2021-02-11 07:25

    I am doing something similar so this question really helps.

    Further to Ash's answer, I found that the above onclick function does not work, I have changed a bit and the form below work just fine to me:

    <% form_tag({ :controller => "votes", :action => "create", :id => @item.id } ) do  %>
        <% for i in 1..10 do %>
          <%=  radio_button_tag :rating, i, false, :onclick => "this.form.submit();" %> <%=h i %> 
        <% end %>
    <% end %>
    

    Hope it would help somebody.

提交回复
热议问题