Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using form_for multi-select fields with acts_as_taggable_on

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
like image 493
kcurtin Avatar asked Feb 01 '12 18:02

kcurtin


1 Answers

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.

like image 112
Batkins Avatar answered Oct 15 '22 15:10

Batkins