0

我在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

谢谢大家的帮助!

4

1 回答 1

0

事实证明,错误发生是因为数据库不喜欢整数查询!

于 2012-08-23T02:26:32.257 回答