我正在尝试使用自定义数据创建一个collection_select选项.我知道如何使用自定义数据属性创建选项,但是当我尝试将这些选项添加到我的collection_select时,我的代码会中断,无论我做什么.
以下代码有效
<%= f.collection_select :tag_ids, Tag.all, :id, :name, {}, {multiple: true} %>
Run Code Online (Sandbox Code Playgroud)
然后我将其修改为,并在下面给出错误
<%= 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>
Run Code Online (Sandbox Code Playgroud)
我用谷歌搜索并尝试了很多变化,但我希望有人可以帮助我形成这一点.
我知道我的代码不包含数据属性,但我简化了我的例子.
我不知道你是否已经解决了这个问题,但这应该有效:
<%= f.select(:tag_ids, options_for_select(Tag.all.map{|t| [t.name, t.id]}), {}, {multiple: true}) %>
| 归档时间: |
|
| 查看次数: |
1184 次 |
| 最近记录: |