Collection_select and options_for_select not working

I am trying to create a collection_select with custom data settings for parameters. I know how to create parameters with custom data attributes, but when I try to add these parameters to my collection, select my code breaks, no matter what I do.

The code below works

<%= f.collection_select :tag_ids, Tag.all, :id, :name, {}, {multiple: true} %>

Then I change it and it breaks, giving an 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 that someone could help me with this.

I know that my code does not include data attributes, but I simplified my example.

+4
source share
1 answer

I don't know if you fixed this, but this should work:

<%= f.select(:tag_ids, options_for_select(Tag.all.map{|t| [t.name, t.id]}), {}, {multiple: true}) %>

+2
source

Source: https://habr.com/ru/post/1541265/


All Articles