Scott
2007-Feb-26 23:41 UTC
boolean db fields set to false fail validation with validates_presence_of?
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? Thanks, Scott --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Scott
2007-Feb-27 14:10 UTC
Re: boolean db fields set to false fail validation with validates_presence_of?
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 this? Thanks, Scott On Feb 26, 6:41 pm, "Scott" <tamosu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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? > > Thanks, > > Scott--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Luke Ivers
2007-Feb-27 15:23 UTC
Re: boolean db fields set to false fail validation with validates_presence_of?
See http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M000941 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] On 2/27/07, Scott <tamosunas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > 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 > this? > > Thanks, > > Scott > > On Feb 26, 6:41 pm, "Scott" <tamosu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > 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? > > > > Thanks, > > > > Scott > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---