[Rails] Re: Re: How To Validate Boolean Form Field

Nithin Reddy jashugan at gmail.com
Thu Mar 2 20:54:02 GMT 2006


or even better...

validates_acceptance_of :toc, {:message => "You must accept this
before proceeding", :allow_nil => false}

On 3/2/06, Nithin Reddy <jashugan at gmail.com> wrote:
> You got me curious about this, so I did some more investigating. It
> seems that the behavior is broken, but you can fix it by doing
> something like this:
>
> class Individual < ActiveRecord::Base
>   validates_acceptance_of :toc, :message => "You must accept this
> before proceeding"
>
>   def validate
>     errors.add(:toc, "You must accept this before proceeding") if self.toc.nil?
>   end
> end
>
> HTH
>
> On 3/1/06, Matthew Feadler <matthew at feadler.com> wrote:
> > Nithin Reddy wrote:
> > > To be able to validate a field, it must be present.
> >
> > Adding :AZ_resident to validates_presence_of throws a validation
> > exception no matter whether True or False is selected.  It's acting as
> > if there's no value in the field.
> >
> > Is this normal behavior for a Boolean form field?
> >
> > Thanks,
> >
> > -ELf
> >
> >
> > --
> > Posted via http://www.ruby-forum.com/.
> > _______________________________________________
> > Rails mailing list
> > Rails at lists.rubyonrails.org
> > http://lists.rubyonrails.org/mailman/listinfo/rails
> >
>


More information about the Rails mailing list