Question

In a Rails 3.2.2 app running on Heroku Cedar stack with Postgres version 9.1.9.
While executing the following method:

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

I run into this error:

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'

"privacy" is defined in the DDL of the heroku database as 'int4 DEFAULT 0'. The app works fine locally with the same rails framework/gems/database, and even when using heroku run console:

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
Was it helpful?

Solution

It turned out it may have been simply a glitch in the db migration, because I've tried to rollback and migrate again and now it seems to work fine. Don't know if the question should be deleted or left in case someone other runs into the same problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top