简体   繁体   中英

Rails - How can I use has_scope with collection_select?

I'm new to rails and I'm using the has_scope gem to help me filter a list to display as a table. I have the has_scope gem setup fine and working for basic parameters (search string, etc.)

How can I get has_scope to recognize the parameters passed in from a collection_select?

I'm doing...

<%= collection_select(:param_val, "company_name", Food.all, :company_name, :company_name, {}, {:multiple => true}) %>

Which passes the URL as

http://localhost:3000/foods?utf8=%E2%9C%93&param_val%5Bcompany_name%5D=McDonalds&commit=Search

And it doesn't filter, just returns the whole list. If I manually adjust the URL to...

http://localhost:3000/foods?utf8=%E2%9C%93&company_name%5D=McDonalds&commit=Search

Then it works fine. So I need to pass ONLY the company_name value, not the entire hash name, but I'm struggling on what I need to change.

For anyone else who runs into this issue, I wasn't able to solve it using the has_scope gem. In my controller I just did this instead...

  if  @company_filter_list.any?
    @filtered_foods = @all_foods.companies(@company_filter_list)  
  end 

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.

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