Ruby on Rails Forms: how to create a CheckBox (or List) table

What is the best way to create a linked set of checkboxes in Ruby on Rails? In the ToscaWidgets library used by Turbogears, you can do the following:

 twf.CheckBoxTable('arbitrary_numbers', 
         num_cols=5, 
         options=['1','2','3','4','5','6','7','8','9','10']),

This generates 10 flagged flags in two lines of 5 flags each. I am trying to duplicate this in Rails without creating 10 separate checkbox controls. It's okay just hoping for a clean way to do it.

+3
source share
1 answer

Something like that:

<% 10.times do |i| %>
  <%= label_tag i %>:
  <%= check_box_tag "alternate_numbers[#{i}]" %> <br />
<% end %>

10 , , params[:alternate_numbers][index], number - . . .

+9

Source: https://habr.com/ru/post/1734781/


All Articles