This almost feels like a bug to me, since false is not nil. (i don''t think!) Using v_p_o on a boolean field fails validation if the field is passed with ''false''. It passes validation in the case of true. How can I validate _presence_of a boolean if it is submitted false? -- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---
Craig Demyanovich
2009-Jan-12 23:17 UTC
Re: validates_presence_of fails with false boolean
You should use validates_inclusion_of. See: http://www.railsbrain.com/api/rails-2.2.2/doc/index.html?a=M001821&name=validates_presence_of Regards, Craig On Mon, Jan 12, 2009 at 5:53 PM, Taylor Strait < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > This almost feels like a bug to me, since false is not nil. (i don''t > think!) Using v_p_o on a boolean field fails validation if the field is > passed with ''false''. It passes validation in the case of true. How can > I validate _presence_of a boolean if it is submitted false? > -- > Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---
Craig Demyanovich wrote:> You should use validates_inclusion_of. See: > > http://www.railsbrain.com/api/rails-2.2.2/doc/index.html?a=M001821&name=validates_presence_of > > Regards, > Craig > > On Mon, Jan 12, 2009 at 5:53 PM, Taylor Strait <Doh. I searched google and ruby-forum, but who would have thought to look in the API docs: "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" Thanks. -- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---