gpt4 book ai didi

ruby-on-rails - 如何在用户按下搜索按钮之前在 meta_search 中设置 0 结果

转载 作者:行者123 更新时间:2023-12-04 06:27:47 25 4
gpt4 key购买 nike

我在我的 rails 3 应用程序上使用 meta_search。默认情况下(在按下搜索按钮之前) meta_search 返回搜索模型的所有元素。我想在用户按下搜索按钮或搜索参数为空之前设置 0 结果。

我使用 meta_search 如下:

def index
@search = Article.search(params[:search])
if params[:search].blank?
@places = nil
else
@places = @search.all
end
end

如果搜索参数为空,设置 0 结果的最佳方法是什么?

谢谢

最佳答案

我不认为 Meta Search 真正提供了开箱即用的东西,但你总是可以欺骗它。

def index
@search = Article.search(params[:search].presence || {:id_lt => 0})
@places = @search.all
end

关于ruby-on-rails - 如何在用户按下搜索按钮之前在 meta_search 中设置 0 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5827910/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com