I am trying to create a collection_select with custom data-attibutes on the options. I know how to create options with custom data attributes, but when I try to add those options to my collection_select my code breaks, not matter what I do.
The code below works
<%= f.collection_select :tag_ids, Tag.all, :id, :name, {}, {multiple: true} %>
I then modify it to and it breaks giving the error below
<%= f.collection_select(:tag_ids, options_for_select(Tag.all.collect{|t| [t.name, t.id]}), {}, {multiple: true}) %>
undefined method `map' for #<ActiveSupport::SafeBuffer:0x00000102df6648>
I have googled and tried many variations, but I was hoping someone could help me form this point.
I know my code does not include data-attributes, but I have simplified my example.
I don't know if you already fixed this but this should work:
<%= f.select(:tag_ids, options_for_select(Tag.all.map{|t| [t.name, t.id]}), {}, {multiple: true}) %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With