[英]Is Ransack has a way to implement token search
Now I have search_field
现在我有
search_field
= f.search_field :name_cont
I want to create a list of extra words(tokens) that will show a different query. 我想创建一个额外的单词(标记)列表,以显示不同的查询。
For example, if I type John
it will show all Johns, but if I type []
it will show all users without a name. 例如,如果我键入
John
,它将显示所有John,但是如果键入[]
,它将显示所有没有名称的用户。
One more: @
- will means users with a name. 还有一个:
@
-表示具有名称的用户。
New implementation also welcome. 也欢迎新的实施。
In the controller, you can modify the search params according to any logic you like. 在控制器中,您可以根据自己喜欢的任何逻辑来修改搜索参数。 Eg, assuming your search params are saved in a
@search_params
(replace with whatever var has your search params, eg params[:q]
): 例如,假设您的搜索参数保存在
@search_params
(用具有您的搜索参数的var替换,例如params[:q]
):
if @search_params[:name_cont] == "[]"
@search_params[:name_blank] = true
@search_params.delete(:name_cont)
end
if @search_params[:name_cont] == "@"
@search_params[:name_present] = true
@search_params.delete(:name_cont)
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.