如何在用户按下搜索按钮之前在 meta_search 中设置 0 结果 [英] How to set a 0 result in meta_search before user pressing a search button
本文介绍了如何在用户按下搜索按钮之前在 meta_search 中设置 0 结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的 rails 3 应用程序上使用了 meta_search.默认情况下(在按下搜索按钮之前) meta_search 返回搜索模型的所有元素.我想在用户按下搜索按钮或搜索参数为空之前设置 0 结果.
I'm using a meta_search on my rails 3 app. By default (before pressing a search button) meta_search returns all elements of searching model. and I want to set 0 result before user pressing a search button or if search params is blank.
我使用 meta_search 如下:
I am using meta_search as follows:
def index
@search = Article.search(params[:search])
if params[:search].blank?
@places = nil
else
@places = @search.all
end
end
如果搜索参数为空,设置 0 结果的最佳方法是什么?
What is the best way to set a 0 result if search params is blank ?
谢谢
推荐答案
我不认为 Meta Search 真正提供了开箱即用的功能,但您总是可以欺骗它.
I don't think that's something that Meta Search really provides out of the box but you can always cheat it.
def index
@search = Article.search(params[:search].presence || {:id_lt => 0})
@places = @search.all
end
这篇关于如何在用户按下搜索按钮之前在 meta_search 中设置 0 结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文