【问题标题】:rails heroku query help PGError: ERROR: operator does not exist: integer ~~ unknownrails heroku query help PGError: ERROR: operator does not exist: integer ~~ unknown
【发布时间】:2023-03-13 12:24:01
【问题描述】:

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

感谢大家的帮助!

【问题讨论】:

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


    【解决方案1】:

    事实证明,错误的发生是因为 DB 不喜欢使用整数进行查询!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-24
      • 2018-11-10
      • 2010-10-20
      • 1970-01-01
      • 2016-10-25
      • 2021-10-01
      • 1970-01-01
      相关资源
      最近更新 更多