0

我创建了一个用于发布专辑评论的应用程序。我添加了一个搜索功能,当我只搜索评论本身时,它在本地和 Heroku 上都可以正常工作。我添加了代码来搜索评论(描述)或专辑标题或艺术家姓名。代码如下所示。它在本地完美运行,但 Heroku 似乎不喜欢下面“OR”的语法。

我将如何更改代码以在本地和 Heroku 上工作?

def self.search(search)
  if search
    losearch = search.downcase
    find(:all, :conditions => ['lower(description) LIKE ? OR lower(artist) LIKE ? OR 
(date) LIKE ? OR lower(album) LIKE ?', "%#{search.downcase}%", "%#{search.downcase}%", "%#{search}%", "%#{search.downcase}%"], order: "created_at desc")
  else
    find(:all, order: "created_at desc")
  end
end

这是我尝试搜索“嘴唇”一词时出现的 Heroku 错误:

2013-05-16T23:31:34.160160+00:00 app[web.1]: Started GET "/pins?search=lips&x=0&y=0" for 173.68.121.123 at 2013-05-16 23:31:34 +0000
2013-05-16T23:31:34.166682+00:00 app[web.1]: Processing by PinsController#index as HTML
2013-05-16T23:31:34.166682+00:00 app[web.1]:   Parameters: {"search"=>"lips", "x"=>"0", "y"=>"0"}
2013-05-16T23:31:34.211501+00:00 app[web.1]: Completed 500 Internal Server Error in 45ms
2013-05-16T23:31:34.213600+00:00 app[web.1]: ActiveRecord::StatementInvalid (PG::Error: ERROR:  operator does not exist: integer ~~ unknown
2013-05-16T23:31:34.213600+00:00 app[web.1]: LINE 1: ...'%lips%' OR lower(artist) LIKE '%lips%' OR (date) LIKE '%lip...
2013-05-16T23:31:34.213600+00:00 app[web.1]: 
2013-05-16T23:31:34.213600+00:00 app[web.1]: HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
2013-05-16T23:31:34.213600+00:00 app[web.1]:                                                              ^
2013-05-16T23:31:34.213600+00:00 app[web.1]: : SELECT "pins".* FROM "pins"  WHERE (lower(description) LIKE '%lips%' OR lower(artist) LIKE '%lips%' OR (date) LIKE '%lips%' OR lower(album) LIKE '%lips%') ORDER BY created_at desc):
2013-05-16T23:31:34.213600+00:00 app[web.1]:   app/models/pin.rb:21:in `search'
2013-05-16T23:31:34.213600+00:00 app[web.1]:   app/controllers/pins_controller.rb:7:in `index'
2013-05-16T23:31:34.213600+00:00 app[web.1]: 
2013-05-16T23:31:34.213600+00:00 app[web.1]: 
4

0 回答 0