Ruby on Rails — multiple selection in f.select

After your { :prompt => "Please select"} add another hash with html options e.g.

<%= f.select(:TYPE, [['Type A', 'Type A'],
                                  ['Type B', 'Type B'],
                                  ['Type C', 'Type C'],
                                  ['Type D', 'Type D'],
                                  ['Type E', 'Type E']
                                 ],{ :prompt => "Please select"},
                                   { :multiple => true, :size => 5 }
                                 ) %>

Once you’ve done this you might want to move your :prompt option (keep the empty {} though so that html attributes don’t get treated as Rails options.)

Also you’ll need to ensure your controller code is correctly accepting and handling multiple values.

Leave a Comment