Forum: Ruby on Rails boolean db fields set to false fail validation with validate

125639ddcc0b9119bb84e29416ace63a?d=identicon&s=25 Scott (Guest)
on 2007-02-27 00:44
(Received via mailing list)
I have a model that contains a :boolean field. In my view, I have a
simple select of Yes or No, which equates to true or false,
respectively. If I choose yes and save, everything works great. If I
choose no, my model fails validation as I have this set as a required
field using validates_presence_of. I have checked the log and it's
definitely set to false, why would this fail validation?


125639ddcc0b9119bb84e29416ace63a?d=identicon&s=25 Scott (Guest)
on 2007-02-27 15:10
(Received via mailing list)
Anyone else seeing this? If not, would someone mind sending me a
snippet of a view/model that used a boolean that doesn't suffer from


2017657725dd1bce83dc8a1e2e991d04?d=identicon&s=25 Luke Ivers (Guest)
on 2007-02-27 16:24
(Received via mailing list)

It basically says that due to some other bits of AR magic, you have to
validate_presence_of kind of funky on boolean variables:
validates_inclusion_of :field_name, :in => [true, false]
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.