2

我有一个Postwhich 可以有多个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 => "&nbsp;", :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 %>

如您所见,这可以允许一次添加一个标签。但是,我想允许在下拉菜单中进行多项选择,以便一次创建多个标签。但是,添加“多个”不起作用:它只会为当前用户创建一个标签,发布帖子。

谁能建议我可以使用单个选择字段来创建多个标签的方法?

4

1 回答 1

2

聚会有点晚了,但我使用了很棒的jQuery Chosen 插件解决了这个问题,它使多个选择看起来非常好。

于 2012-06-25T18:46:26.237 回答