【发布时间】:2011-11-09 10:12:18
【问题描述】:
我有一个Post,它可以有多个Tags,每个都与一个User 相关(想想Facebook 标记)。
在我的 Post 表单中,我有这个 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 %>
如您所见,这可以允许一次添加一个标签。但是,我想允许在下拉菜单中进行多项选择,以便一次创建多个标签。但是,添加“多个”不起作用:它只会为当前用户创建一个标签,发布帖子。
谁能建议我可以使用单个选择字段来创建多个标签的方法?
【问题讨论】:
-
我也对此问题的解决方案感兴趣。
标签: ruby-on-rails-3 has-many formtastic fields-for