所以现在当我搜索“cook”时,我的搜索会返回cookie。
我需要它返回“cook”然后如果什么都不存在则返回“cookies”
class SearchesController < ApplicationController
def search
@sentence = Sentence.where("LOWER(verse) LIKE LOWER(?)", "%" + params[:search_term] + "%")
respond_to do |format|
format.html
end
end
答案 0 :(得分:1)
你可以尝试这个,但可能不是有效的,因为它会进行两次查询:
@sentence = Sentence.where("LOWER(verse) LIKE LOWER(?)", params[:search_term])
@sentence_alternatives = Sentence.where("LOWER(verse) LIKE LOWER(?)", "%#{params[:search_term]}%") if @sentence.blank?
另一种方法是将or
与where
:
@sentence = Sentence.where("LOWER(verse) LIKE LOWER(?)", params[:search_term]).or.where("LOWER(verse) LIKE LOWER(?)", "%#{params[:search_term]}%")
答案 1 :(得分:0)
@sentence = Sentence.where("LOWER(verse) LIKE LOWER(%?%)", params[:search_term])