I am using the ransack gem for my rails app and have a problem with multiselect. I have a job and a company model, a company has many jobs, a job belongs to a company. I want to perform a search on jobs so people can see jobs from specific companies, I have done some research and apparently this should work in the search form:
= search_form_for @q do |f|
= f.collection_select :company_name_cont, Company.all, :id, :name, {:multiple => true}, class: 'chosen-it'
= f.submit "search"
So in the view I get the list (with autocomplete from the chosen gem) but when I click on search it returns no result and I can't select multiple companies.
However, when I use a search field instead like this:
= f.search_field :company_name_cont
The search works.
Could you help me guys
Thanks a lot
You should use company_name_in
instead of company_name_cont
:
= f.collection_select :company_name_in, Company.all, :id, :name, {}, {:multiple => true}
More info can be found in ransack's wiki here: https://github.com/activerecord-hackery/ransack/wiki/Basic-Searching#in
In general, we can write this as
= f.collection_select :some_id_in, Model.all, :id, :name, {}, {:multiple => true}
where some_id is a model attribute for which we have multiple select value for filter.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.