我的基本搜索不起作用,我不明白为什么。
在我的模型中我有这个
def self.search(search)
if search
search_condition = "%" + search + "%"
find(:all, :conditions => ['jobTitle LIKE ? OR jobDescription LIKE ?', search_condition, search_condition])
end
end
参数确实传递给它,然后出现错误:
PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: "all" LINE 1: ...ngs".* FROM "postings" WHERE "postings"."id" IN ('all', '--... ^ : SELECT "postings".* FROM "postings" WHERE "postings"."id" IN ('all', '--- :conditions: - jobTitle LIKE ? OR jobDescription LIKE ? - "%drew%" - "%drew%" ')
我做错了什么吗?
最佳答案
您正在使用过时的查找语法
。使用 where
代替:
def self.search(search)
if search
search_condition = "%" + search + "%"
where(['jobTitle LIKE ? OR jobDescription LIKE ?', search_condition, search_condition])
end
end
关于ruby-on-rails - Rails 简单搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25416465/