Reputation: 1017
I am trying to get a multi select dropdown working in Rails. The code is:
<div class="field">
<%= f.label :tag_id %><br>
<td><%= f.collection_select(:tag_id, Tag.all, :id, :name, {:multiple => true})%></td>
I've also tried
<td><%= f.collection_select(:tag_id, Tag.all, :id, :name, :multiple true)%>
I thought that I should be able to hold the shift or ctrl and click on multiple items to select more than one item
I suspect that the problem could be in the schema for the documents table that is linked to the Tags model. .
t.integer "tag_id"
The documents model has
class Document < ActiveRecord::Base
. . .
belongs_to :tag
. . .
end
and the tag model has has_many_documents
Upvotes: 0
Views: 70
Reputation: 33552
The below should work
<%= f.collection_select(:tag_id, Tag.all, :id, :name, {}, {:multiple=> true})%>
You should pass it as the last argument(i.e, html_options = {}
), but currently you are passing it in options = {}
.
Upvotes: 1