Re: validation help please

Walther Diechmann
Fri, 01 Mar 2013 13:46:15 -0000

Hi Dave,

I believe you should do something along the lines of

Model:

	validates_each :question do |record, attr, value|
		record.errors.add attr, ''The question is not present!?'' if
value.blank? and record.question_type=="standard"
	end

plz correct me if I''m wrong, Colin :)

cheers,
Walther


Den 01/03/2013 kl. 14.20 skrev Dave Castellano
<lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>:

> 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
>    ...
>
> Controller:
> def create
>    @question = Question.new(params[:question])
>  if @question.save
>          if params[:question_type] == "standard"
>            flash[:success] = "Question created!"
>            redirect_to @question
>          else
>            .....
>
> new.html.erb:
> <%= f.submit ''Save'', question_type:
"standard" ...
>
> --
> 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 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
> For more options, visit https://groups.google.com/groups/opt_out.