2015-10-09 75 views
0

我想要在Rails中使用多选择下拉菜单。该代码是:ruby​​中的collection_select不允许多选择

<div class="field"> 
<%= f.label :tag_id %><br> 
<td><%= f.collection_select(:tag_id, Tag.all, :id, :name, {:multiple => true})%></td> 

我也试过

<td><%= f.collection_select(:tag_id, Tag.all, :id, :name, :multiple true)%> 

我认为我应该可以按住Shift或Ctrl键并单击多个项目选择多个item

我怀疑问题可能出现在链接到标签模型的文档表的模式中。 。

t.integer "tag_id" 

的文件模型

class Document < ActiveRecord::Base 
. . . 
    belongs_to :tag 
    . . . 
end 

和标签模型has_many_documents

  1. 是否多实际上f.collection_select工作
  2. 我应该使用比'以外的东西belongs_to:标记?

回答

1

下面应该工作

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

你应该把它作为最后一个参数(即,html_options = {}),但目前要传递它options = {}

+1

这适用于多选。谢谢 –

相关问题