1

I'm using Slim Select for my select fields in my Rails 6 app. In order to allow users to select multiple options in the select, I have to add the attribute multiple to my select tag.

So it renders HTML, like: <select id="foo" multiple>.

How do I get multiple to show in the select tag?

I've read:

And I've tried:

<%= f.collection_select :foo, Tag.order(:name),:id,:name, include_blank: true, :html => 'multiple' %>

<%= f.collection_select :foo, Tag.order(:name),:id,:name, include_blank: true, input_html: { data: { multiple: "required"} } %>

<%= f.collection_select :foo, Tag.order(:name),:id,:name, include_blank: true, :html => {:multiple => true}  %>

<%= f.collection_select :foo, Tag.order(:name),:id,:name, include_blank: true, multiple: true %>

<%= f.collection_select :foo, Tag.order(:name),:id,:name, include_blank: true, :multiple => true %>

However, none of these add multiple in the select tag.

yellowreign
  • 3,528
  • 8
  • 43
  • 80

1 Answers1

0

make sure :foo is an array that can save multiple ids, and put multiple: true as follow

<%= f.collection_select :foo, Tag.order(:name),:id,:name, {} , {multiple: true, class: '...'} %>
widjajayd
  • 6,090
  • 4
  • 30
  • 41
  • Thank you for your help! For some reason, after I changed it, the JS works correctly, but I can an error saying that it's unpermitted parameter? When I revert the code, it posts OK (the parameter's been whitelisted in the controller. – yellowreign May 30 '20 at 01:08
  • Sorry, I figured it out. Thanks for the array part in your answer, I was missing `: [ ]` in the allowed params. – yellowreign May 30 '20 at 01:13