Multiple Rail Switch Sets

Is there a way to configure two groups of radio buttons in Rails? I can imagine that you could put them in separate forms, perhaps, but is there a way to create two sets of radio buttons in the same form?

+5
source share
3 answers

Yes, you can create two different sets simply by using a different radio button name:

radio_button_tag 'gender', 'male'
radio_button_tag 'gender', 'female'

radio_button_tag 'food', 'none'
radio_button_tag 'food', 'vegetarian'
radio_button_tag 'food', 'vegan'

This will cause params [: gender] to be “male” or “female”, and params [: food] to be “no,” “vegetarian,” or “vegan.” You can do the same with the radio_button function.

+6
source

name. , Rails- .

, radio_button , .

+2

My suggestion is to use radio_button_tag with a simple loop. Here you can display the selected value without the corresponding model using form_tag.

<%= form_tag methods: :post do  %>
  <% (0..10).each do |value| %>
    <%= radio_button_tag 'store', value, :required => true %>
  <% end %>
  <%=  submit_tag 'submit' %>
<% end %>
Run code
0
source

All Articles