Rails,searchlogic选择带复选框的类别

atm*_*ell 2 ruby ruby-on-rails

我正在使用searchlogic来搜索一些画作.每幅画都属于一个类别.我想要做的是在我的搜索表单中添加多个复选框,以便用户可以标记多个类别.(与or一起使用)这可能与searchlogic一起使用吗?我正在寻找的查询是这样的:

SELECT * FROM paintings WHERE category LIKE "white" OR category LIKE "red"...

f.check_box :category (white)
f.check_box :category (black)
f.check_box :category (red)
f.check_box :category (green)
Run Code Online (Sandbox Code Playgroud)

等等

Jar*_*dom 5

这是超级简单的方法(假设你的搜索对象是@search):

f.check_box :category_equals_any, {:name => "search[category_equals_any][]"}, "white"
f.check_box :category_equals_any, {:name => "search[category_equals_any][]"}, "black"
f.check_box :category_equals_any, {:name => "search[category_equals_any][]"}, "red"
f.check_box :category_equals_any, {:name => "search[category_equals_any][]"}, "green"
Run Code Online (Sandbox Code Playgroud)