rails heroku query help PGError:ERROR:运算符不存在:整数~~未知

时间:2012-08-22 16:32:51

标签: ruby-on-rails-3 activerecord heroku

我在heroku中使用ruby 1.9.3部署rails 3.2.8,本地查询将所有书籍显示为结果或没有,并且在heroku中它只显示以下错误。

Started GET "/books/advanced_search?utf8=%E2%9C%93&title=elinor&author=&isbn=&commit=Search" for 157.253.204.87 at 2012-08-22 15:38:03 +0000

Parameters: {"utf8"=>"✓", "title"=>"elinor", "author"=>"", "isbn"=>"", "commit"=>"Search"}
Processing by BooksController#advanced_search as HTML
Rendered books/advanced_search.html.erb within layouts/application (24.0ms)
Completed 500 Internal Server Error in 25ms

ActionView::Template::Error (PGError: ERROR:  operator does not exist: integer ~~ unknown
LINE 1: ...tle LIKE '%elinor%' and author LIKE '%%' and isbn LIKE '%%')

HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

我试图通过标题找到我的迷你目录中的书籍,标题是一个字符串,作者是一个文本,isbn是一个整数,由他们中的任何一个或所有人。

继承我的疑问:

@books = Book.paginate(
      page: params[:page], per_page: 10,
      :conditions => ['
                    title like ? ||
                    author like ?  ||
                    isbn like ?',
          { :title => "%#{params[:title]}%",
            :author => "%#{params[:author]}%",
            :isbn => params[:isbn].to_i
          }
      ]
  ) 

继承模特:

class Book < ActiveRecord::Base
  attr_accessible :author, :isbn, :title, :description
  has_many :reviews, dependent: :destroy
  has_many :ratings, dependent: :destroy

  validates :author,      presence: true
  validates :description, presence: true
  validates :isbn,        presence: true
  validates :title,       presence: true


end

谢谢大家的帮助!

1 个答案:

答案 0 :(得分:0)

事实证明错误发生是因为DB不像整数查询那样!