在返回产品搜索结果后,我需要在单个模型期刊上执行搜索.
有没有办法只使用完整字符串的一部分来搜索期刊标题?
def index
@product_results = Gemgento::Search.products(params[:query])
@editorial_results = Journal.where("headline LIKE ?", "#{params[:query]}")
end
Run Code Online (Sandbox Code Playgroud)
例如.假设我的上一个日志对象有标题:"stack overflow blogpost"如果我查询活动记录:
@editorial_results = Journal.where("headline LIKE ?", "stack overflow")
Run Code Online (Sandbox Code Playgroud)
就像我现在一样,它仍然需要在字符串上直接匹配.
通过http://guides.rubyonrails.org/active_record_querying.html搜索似乎这是正确的方法,尽管sql注入的警告.
有没有办法构建搜索,以便它将返回最后一个条目?(不使用搜索库?)