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.

1 Answer 1

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: '...'} %>
Sign up to request clarification or add additional context in comments.

2 Comments

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.
Sorry, I figured it out. Thanks for the array part in your answer, I was missing : [ ] in the allowed params.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.