Ruby on Rails — multiple selection in f.select

前端 未结 5 517
故里飘歌
故里飘歌 2020-12-02 15:21

I have the following select box in my form:

Related Type:   <%= f.select(:TYPE, [[\'Type A\', \'Type A\'],
                                  [\'T         


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 16:01

    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.

提交回复
热议问题