Rails treats an integer field with 0 and 1 as a boolean. The
checkbox_field helpers know what to do with 0 and 1 values, and scaffold
generators create pulldowns for those fields with “True” and “False” on
the labels and 0 and 1 as the return values.
If you use migrations to maintain your database schema, a command like
add_column :salespeople, :has_been_trained, :boolean, :default =>
will create the appropriate field type for you. On MySQL this generates
a tinyint(1) in the salespeople table, with a default of 0.
Brendan Baldwin wrote:
Hey all –
I’ve been using enumerable char(1)'s with ‘y’ and ‘n’ values for my
Boolean columns in Rails, but it strikes me there should be a better
How do you setup columns that represent true/false-ness in your
schemas on Rails?
Wondering what kind of standard approaches there are other than me
writing something like
class MyEntity < ActiveRecord::Base
return false unless active==‘y’
– Brendan Baldwin (dot com)