Ruby-on-rails 使用带有acts_as_taggable_on 的form_for 多选字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9100808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using form_for multi-select fields with acts_as_taggable_on
提问by kcurtin
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
回答by Batkins
There needs to be two pairs of brackets, one for the options, and one for html_options, like so:
需要有两对括号,一对用于options,一对用于html_options,如下所示:
<%= f.select :skills_list, options_for_select(["Asst", "dir", "pres"]), {}, {:multiple => true, :class => "chzn-select", :style => "width:450px;" } %>

