[英]How do I enable multiple selection for option_form_collection?
I can't figure out how to enable multiple selection for a input in Ransack . 我不知道如何在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 %>
The multiple: true does not work as I expected. 倍数:true不符合我的预期。 It only show a normal dropdown box not a multiple selection box.
它仅显示一个普通的下拉框,而不显示多个选择框。
My first question is how to enable multiple selection ? 我的第一个问题是如何启用多重选择?
And my Second question is how do I keep the selected value and show it after the page loaded in selection box ? 我的第二个问题是如何保留所选值并在选择框中加载页面后显示它?
我找到了答案
<%= 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.