views:

33

answers:

1

Does rails have a validator like validates_numericality_of for boolean or do I need to roll my own?

+2  A: 

I believe for a boolean field you will need to do something like:

validates_inclusion_of :field_name, :in => [true, false]

From an older version of the API: "This is due to the way Object#blank? handles boolean values. false.blank? # => true"

I'm not sure if this will still be fine for Rails 3 though, hope that helped!

Sonia
lol @ Rails 3. I can bet this will be the caveat for months to come. Ok, I thought this migth have been it and you agree. Thanks!
DJTripleThreat