使用基于聚合的动态过滤器的 Filter Rails 3 模块
我有一个模型,其中包含公司名称、发布(日期)、位置(纬度/经度对)等属性。在索引视图中,我使用 will_paginate gem 对结果集进行分段。
我想包括基于查询结果的动态过滤器。例如,如果选择老化桶,则其他过滤器将基于此限制。理想情况下,我能够按频率对某些值进行排序。比如:
Posted: [ 0 (24) | 30 (51) | 60 (45) | 90+ (555) ]
Company: [ Company X (53) | Company AAA (44) | ... ]
Locations: [ New York (100) | Paris (51) | ... ]
我考虑过使用辅助函数来根据结果的集合来计算聚合,但是 will_paginate gem 的集合(例如@foos)仅包含当前页面的结果。也许有一种方法可以访问整个结果集。
我想我可以执行一系列 SQL 语句来计算每个过滤器的频率值,但我希望可能有一种更有效的方法来执行此操作。
I have a model that includes attributes like company_name, posted (a date), location (lat/lng pair). In the Index view, I segment the result set using the will_paginate gem.
I would like to include dynamic filters that are based on the query's results. For example, if an aging bucket is chosen, the other filters would be based on this restriction. Ideally, I would be able to sort some of the value by frequency. Something like:
Posted: [ 0 (24) | 30 (51) | 60 (45) | 90+ (555) ]
Company: [ Company X (53) | Company AAA (44) | ... ]
Locations: [ New York (100) | Paris (51) | ... ]
I thought about using a helper function to calculate the aggregates based on the result's collection, but the will_paginate gem's collection (e.g. @foos) only includes the current page's result. Perhaps there is a way to access the entire result set.
I suppose I could execute a series of SQL statements to calculate each filter's frequency values, but I was hoping there might be a more-efficient way of doing this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过以下方法取得了一些成功:
controller:
view:
也许有一种更干燥/更有效的方法来做到这一点。
I've had some success with the following approach:
controller:
view:
Perhaps there is a DRYer/more-efficient way to do this.