2

I have a Post which can have multiple Tags, each of which relates to a User (think Facebook tagging).

In my Post form I have this Formtastic code:

<%= 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? && [email protected]_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 %>

As you can see this can allow a tag to be added one at a time. However I'd like to allow multiple selections in the dropdown menu, to create multiple tags in one go. Adding "multiple" doesn't work, however: it simply results in creating a tag for the current user, posting the Post.

Can anyone suggest a way I can use a single select field to create multiple tags?

1
  • I am interested in the solution to this as well. Commented Nov 16, 2011 at 2:46

1 Answer 1

2

A bit late to the party, but I solved this problem using the awesome jQuery Chosen plugin which makes multiple selects look really good.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.