在带有 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