Most of the time when I create a model with a boolean attribute I don’t actually
use a boolean in the database. A popular example is published on a blog post,
being implemented via setting the publish_date.
This means that in Rails to use form_for you just need to define the accessors
on the model and everything should work, except it doesn’t because the form
returns “0” for false and “1” for true, as strings. A real ActiveRecord model
gets around this by converting the values to boolean before setting. Since it is
tedious to implement time and time again it is easy to just reuse the Rails
internal function.
ActiveRecord::ConnectionAdapters::Column.value_to_boolean("0")
=> false
ActiveRecord::ConnectionAdapters::Column.value_to_boolean(“1”)
=> true
Quick and easy!
Enjoy.