Question

I can't figure out how to enable multiple selection for a input in 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. 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 ?

Was it helpful?

Solution

I found the answer

<%= f.select :country_code_in, Country.all.map {|country| [country.name,country.code] }, {include_blank: 'All'}, {multiple: true}  %> 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top