Forum: Ruby on Rails ActiveRecord validates_presence_of with false

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
B67f1094ad4e3716efd63ef1b8582c56?d=identicon&s=25 Hendy Irawan (Guest)
on 2007-07-28 08:42
(Received via mailing list)
Hi Rails

I can't seem to use a boolean value 'false' with validates_presence_of.
It always fails.

I even tried using 'f'.

What's the proper way to set a false value?

Isn't false a "present" value in a boolean column?

What I want is to require either true or false, but prevent nil :)

Thank you

Hendy Irawan
881b7dd91c0d9287aea5bc505c10a15a?d=identicon&s=25 Ryan Carmelo Briones (Guest)
on 2007-07-28 17:20
(Received via mailing list)
Hendy Irawan wrote:
> What I want is to require either true or false, but prevent nil :)

From the API docs for validates_presence_of:

"If you want to validate the presence of a boolean field (where the real
values are true and false), you will want to use validates_inclusion_of
:field_name, :in => [true, false] This is due to the way Object#blank?
handles boolean values. false.blank? # => true"

This should do the trick!

Ryan Carmelo Briones

View this message in context:
Sent from the RubyOnRails Users mailing list archive at
This topic is locked and can not be replied to.