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

DBは整数を使用したクエリを好きではないため、エラーが発生したことが判明しました!

于 2012-08-23T02:26:32.257 に答える