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 www.hendyirawan.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ryan Carmelo Briones
2007-Jul-28 15:19 UTC
Re: ActiveRecord validates_presence_of with false
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: http://www.nabble.com/ActiveRecord-validates_presence_of-with-false-tf4161367.html#a11843712 Sent from the RubyOnRails Users mailing list archive at Nabble.com. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---