Using form_for multi-select fields with acts_as_taggable_on

kcurtin picture kcurtin · Feb 1, 2012 · Viewed 23.4k times · Source

I can't figure out the right code for using a predetermined set of options for a multi-select field. I want to have a list of skills in a drop down that users can select from. Here is the code I am using, it works fine as a single select field, but not as a multi-select:

 <%= form_for(@user, :html => { :class => "form-stacked" } )  do |f| %>
 ...
   <div class="clearfix"><%= f.select :skill_list, options_for_select(["Asst", "dir",      "pres"]), 
     {
    :multiple => true, 
    :class => "chzn-select", 
    :style => "width:450px;" } %></div>
 ...
 <% end %>

Anyone have any suggestions? Eventually, I will want to store all of the options for the multi-select form elsewhere because there will be a bunch, but this is the first challenge I can't figure out..

Thanks.


EDIT

I have also tried:

:html => { :multiple => true, :class => "chzn-select", :style => "width:450px;" } and it doesnt work either

Answer

Batkins picture Batkins · Feb 1, 2012

There needs to be two pairs of brackets, one for the options, and one for html_options, like so:

<%= f.select :skills_list, options_for_select(["Asst", "dir", "pres"]), {}, {:multiple => true, :class => "chzn-select", :style => "width:450px;" } %>

See the docs for the select helper.