Ruby on Rails 4 - simple_form multiple select input

社会主义新天地 提交于 2019-11-29 03:04:46
user3177153
f.input :days, collection: @your_collection, input_html: { multiple: true }

It actually does work the way I wanted it to. The trick is to tell the strong parameters to allow a hash. It doesn't throw a strong parameters error, the param just gets thrown out and doesn't come through. So I set it to for example: params.require(:survey).permit(:particular_users => []).

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' %>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!