我想讓我的搜索方法爲Heoku工作。我之前遇到過這個問題,並將.downcase添加到它中。 但現在,它不工作,我得到 未定義的方法`downcase」的零:NilClass未定義的方法downcase
listing.rb
def self.locsearch(search_location, search_description)
return scroped unless search_location.present? && search_description.present?
where(["LOWER(location) LIKE? AND LOWER(description) LIKE?", "%#{search_location.downcase}%", "%#{search_description.downcase}%"])
end
有誰知道問題是什麼?
我改成了
def self.locsearch(location, description)
if location.present? && description.present?
where(["LOWER(location) LIKE? AND LOWER(description) LIKE?", "%#{location.downcase}%", "%#{description.downcase}%"])
else
self.all
end
end
現在它返回的所有目錄,即使我的位置和說明,輸入相匹配的某些上市。 爲什麼?
謝謝馬克,這個作品。我用self.all代替了scroped(意思是有範圍的,但我用它錯了)。 – Rika 2014-10-09 20:12:25