Re: validation help please

Frederick Cheung
Fri, 01 Mar 2013 15:35:11 -0000

On Friday, March 1, 2013 2:58:53 PM UTC, Ruby-Forum.com User
wrote:
>
> > with the :if option
> >
> > validates :question_type,     :presence  => true
> > validates :question,        :presence   => true, :if =>
> > :standard_question?
> >
> > will call the standard_question? method and only enforce the presence
> > validation on question if the method returns true. There is also a
> > lambda
> > form
> >
> > validates :question,        :presence   => true, :if => lambda
{|record|
> > record.question_type == ''standard''}
> >
> > Fred
>
> Thanks Fred,
> Got this error
> undefined method `standard_question?'' for
#<Question:0x007f947ddb2e00>
> Do I need to write a  standard_question method
>
> Yes - it''s up to you to write a standard_question? method. The
lambda
saves you having to have the condition in a separate method but can make
your validation look more cluttered (especially for more complicated
conditions).

Fred

--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit