4

在带有 Postgres 版本 9.1.9 的 Heroku Cedar 堆栈上运行的 Rails 3.2.2 应用程序中。
在执行以下方法时:

class Post < ActiveRecord::Base
  def shared_to_all
    privacy & 1 == 1
  end
end

我遇到了这个错误:

Completed 500 Internal Server Error in 19ms

NoMethodError (undefined method `&' for "0":String):
  app/models/post.rb:75:in `shared_to_all'
  app/controllers/application_controller.rb:212:in `next_post'

“隐私”在 heroku 数据库的 DDL 中定义为“int4 DEFAULT 0”。该应用程序使用相同的 rails 框架/gems/数据库在本地运行良好,即使使用 heroku 运行控制台:

irb(main):008:0> Post.first.shared_to_all
=> false
irb(main):009:0> Post.first.privacy.class
=> Fixnum
irb(main):010:0> Post.first.privacy & 1 == 1
=> false
4

1 回答 1

1

事实证明,这可能只是数据库迁移中的一个小故障,因为我试图回滚并再次迁移,现在它似乎工作正常。不知道是否应该删除或留下问题,以防其他人遇到同样的问题。

于 2013-05-12T21:54:42.183 回答