[英]Rails handle multiple Params in search query
I have the following model and I want to pass multiple params in "with_query", don't know how to achieve it. 我有以下模型,我想在“ with_query”中传递多个参数,不知道如何实现。 currently you can see it takes only "query" param. 当前,您可以看到它仅需要“查询”参数。 how can I filter it with country and job_type. 如何使用country和job_type对其进行过滤。 any help would be really appreciated. 任何帮助将非常感激。
search Model 搜索模型
def self.search(query, country, job_type, page = 1)
results = []
Refinery.searchable_models.each do |model|
results << model.limit(RESULTS_LIMIT).with_query(query)
end if query.present?
results.flatten[0..(RESULTS_LIMIT - 1)]
end
Controller 调节器
def show
@results = Refinery::SearchEngine.search(params[:query], params[:country], params[:job_type], params[:page])
present(@page = Refinery::Page.find_by_link_url("/search"))
end
我会尝试将在搜索模型中建立结果的行更改为:
results << model.limit(RESULTS_LIMIT).with_query(query).where(country: country, job_type: job_type)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.