Searchkick 按按钮过滤

Searchkick filtering by buttons

我有一个'feed'模型,其中has_many个条目,这些都显示在一页上。 Searchkick 已全部设置好,使用默认搜索栏就像一个魅力,但不幸的是我似乎无法弄清楚如何使用按钮来完成它。

我正在尝试使用 Searchkick 通过单击按钮进行搜索(单击 Color Brandy,获取与颜色 Brandy 匹配的所有结果等)。我在它的文档中看到这叫做 'Aggregation',一个例子是 { color: "brandy" }.

我是否必须为 controller/model 中的每个过滤器创建单独的方法?然后单击按钮呼叫他们?我将如何处理多个?

不,您不会向控制器添加新操作。扩展 Searchkick 文档中的聚合示例:

in the controller

def filters
  allowed_filters = %w(color size)
  filters = params.select{|k, v| allowed_filters.include?(k) }
end
helper_method :filters

in the view

= link_to 'color brandy', {action: 'index', filters.merge(color: 'brandy'}, class: 'ui-button'