Re: validation help please

Colin Law
Fri, 01 Mar 2013 13:33:45 -0000

On 1 March 2013 13:20, Dave Castellano
<lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>
wrote:
> Hi,
>
> Can anyone take a look at this....  i''ve been banging my head on
the
> wall for several days trying to figure this out.  I can''t figure
out why
> the validation is bypassed.  The only clue I have is it seems its not
> evaluating :question_type == "standard"  to true.
>
> Model:
> validates :question_type,     :presence  => true
>     if :question_type == "standard"
>       validates :question,        :presence   => true

Is that code just inline in the model?  If so then it is only executed
once, when the code is loaded, so the if statement is not tested for
each object being validated.  Have a look at the Rails Guide on
ActiveRecord Validations and Callbacks to see ways that you can
accomplish what you want.

Colin