简体   繁体   English

Rails-如何将has_scope与collection_select一起使用?

[英]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. 我是Rails的新手,并且使用has_scope gem帮助我过滤列表以显示为表格。 I have the has_scope gem setup fine and working for basic parameters (search string, etc.) 我的has_scope gem设置很好,并且可以处理基本参数(搜索字符串等)

How can I get has_scope to recognize the parameters passed in from a collection_select? 如何获得has_scope来识别从collection_select传入的参数?

I'm doing... 我正在做...

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

Which passes the URL as 哪个将URL作为

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. 因此,我只需要传递company_name值,而不是整个哈希名称,但是我正在为需要更改的内容而苦苦挣扎。

For anyone else who runs into this issue, I wasn't able to solve it using the has_scope gem. 对于遇到此问题的其他人,我无法使用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 

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

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