Multiple radio button groups who send data in an array

后端 未结 1 1694
长发绾君心
长发绾君心 2021-01-07 00:56

I\'ve tried the following:

<%= form_for .... do |f| %>
    <%= f.label \"test1\" %>
        <%= radio_button_tag \'value[]\', \"1\" %>
             


        
1条回答
  •  花落未央
    2021-01-07 01:17

    Try this and let me know what happens:

    <%= form_for .... do |f| %>
      <%= f.label 'test1' %>
        <%= radio_button_tag 'value[group_one]', '1' %>
        <%= radio_button_tag 'value[group_one]', '2' %>
      <%= f.label 'test2' %>
        <%= radio_button_tag 'value[group_two]', '1' %>
        <%= radio_button_tag 'value[group_two]', '2' %>
      <%= f.submit 'test_send' %>
    <% end %>
    

    You should be able to get your data in the controller with params[:value] and then params[:value][:group_one] and params[:value][:group_two].

    0 讨论(0)
提交回复
热议问题