Ruby on Rails 4 - simple_form multiple select input

后端 未结 3 930
臣服心动
臣服心动 2020-12-16 11:10

I have a simple_form input field that looks like this:

<%= f.input :particular_users, collection: @all_users, input_html: { class: \'multiselectuser\', mu         


        
3条回答
  •  春和景丽
    2020-12-16 11:39

    To create multiple select tags with simple_form, use:

    <%= f.association :particular_users, collection: @all_users, input_html: { class: 'multiselectuser'} %>
    

    see part Associations in the gem description.

    But as you don't want to use an ActiveRecord associaion, use select_tag:

    <%= select_tag 'particular_users', 
           options_from_collection_for_select(@all_users, :id, :name), 
           multiple: true, class: 'multiselectuser' %>
    

提交回复
热议问题