Rails - Boolean field not saved on PostgreSQL / Heroku Rails - Boolean field not saved on PostgreSQL / Heroku heroku heroku

Rails - Boolean field not saved on PostgreSQL / Heroku


Make sure that you restart your app.

http://devcenter.heroku.com/articles/rake

Once you run migrations that add new columns, you have to manually restart your app on heroku with "heroku restart" so that Rails will pick up the changes.


Looks like the problem was on the RAILS side.

Once I manually updated the values to false:

ActiveRecord::Base.connection.execute("UPDATE users SET send_contact_emails=FALSE")

The problem disappeared.

(As if rails 2.3.10 was unable to handle 'nil' in boolean fields..)


Boolean in Rails uses tinyint column type, so it's 1/0 on DB level side.

API

ClassActiveRecord::ConnectionAdapters::MysqlAdapter < AbstractAdapteremulate_booleansBy default, the MysqlAdapter will consider all columns of type tinyint(1) as boolean. If you wish to disable this emulation (which was the default behavior in versions 0.13.1 and earlier) you can add the following line to your environment.rb file:  ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans = false