繁体   English   中英

如何为option_form_collection启用多项选择?

[英]How do I enable multiple selection for option_form_collection?

我不知道如何在Ransack中为输入启用多重选择。

<%= search_form_for @q,url: search_table_path do |f| %> 
   <%= f.label :country_code_eq %>

   <%= f.select :country_code_eq, 
    options_from_collection_for_select(Country.all, :code, :name),
    {prompt: 'Select a Country',multiple: true,include_blank: false}%> 

   <%= f.label :date_start %>
   <%= f.text_field :date_start %>
   <%= f.submit %> 
<% end %>

倍数:true不符合我的预期。 它仅显示一个普通的下拉框,而不显示多个选择框。

我的第一个问题是如何启用多重选择?

我的第二个问题是如何保留所选值并在选择框中加载页面后显示它?

我找到了答案

<%= f.select :country_code_in, Country.all.map {|country| [country.name,country.code] }, {include_blank: 'All'}, {multiple: true}  %> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM