私はPost
複数を持つことができるを持っていますTags
、それぞれはUser
(Facebookのタグ付けを考えてください)に関連しています。
私の投稿フォームには、次のFormtasticコードがあります。
<%= f.inputs :class => 'tags' do %>
<ul>
<%= f.semantic_fields_for :tags do |t| %>
<% if t.object.new_record? %>
<%= t.input :user_id, :label => " ", :input_html => { :class => 'chosen', :'data-placeholder' => 'Select connection' }, :as => :select, :collection => current_user.connections %>
<% end %>
<% end %>
</ul>
<% if @post.tags.present? && !@post.new_record? %>
<ul class="existing-tags">
<%= f.fields_for :tags do |t| %>
<% unless t.object.new_record? %>
<li>
<%= link_to avatar(t.object.user), user_path(t.object.user) %>
<%= t.check_box :_destroy %>
<%= t.label :_destroy, 'Remove' %>
</li>
<% end %>
<% end %>
</ul>
<% end %>
<% end %>
ご覧のとおり、これにより、タグを一度に1つずつ追加できます。ただし、ドロップダウンメニューで複数の選択を許可して、一度に複数のタグを作成したいと思います。ただし、「複数」を追加しても機能しません。つまり、現在のユーザーのタグが作成され、投稿が投稿されます。
単一の選択フィールドを使用して複数のタグを作成する方法を誰かが提案できますか?