gpt4 book ai didi

ruby-on-rails - 使用 form_for 多选字段和acts_as_taggable_on

转载 作者:行者123 更新时间:2023-12-03 02:04:14 25 4
gpt4 key购买 nike

我无法找出为多选字段使用一组预定选项的正确代码。我希望在下拉列表中提供一个可供用户选择的技能列表。这是我正在使用的代码,它作为单个选择字段可以正常工作,但不能作为多选字段:

 <%= 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 %>

大家有什么建议吗?最终,我想将多选表单的所有选项存储在其他地方,因为会有很多选项,但这是我无法解决的第一个挑战..

谢谢。

<小时/>

编辑

我也尝试过:

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

最佳答案

需要有两对括号,一对用于 options,一对用于 html_options,如下所示:

<%= 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 .

关于ruby-on-rails - 使用 form_for 多选字段和acts_as_taggable_on,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9100808/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com