Skipping validaiton

I have a form that posts back to itself (form action = current browser
URL),
and the validations work properly. I use a little code to determine
whether
they’ve entered information, so if they leave and come back they don’t
have
to refill out the form:

Create new order or get from session

if session[:order].nil?

        @order = Order.new

session[:order] = @order

else

        @order = session[:order]

end

but now, if they just visit the page (issuing a GET statement), the page
thinks there are errors and shows the error box. Is there a way to skip
error validation for a GET statement? Like:

don’t show model errors

if request.get?

        # some magic line to skip model validation

End

Thanks,

Chad

case @request.method
when :post
…etc…
when :get
…etc…
end

harp

it’s the …etc… under your “when :get” that I’m looking for…

thanks though

Try for your magic code:

if session[:order].nil?

        @order = Order.new

session[:order] = @order

else
@order = session[:order].send :instance_variable_set, :@attributes,
session[:order].attributes_before_type_cast
end

The problem (probably) is you’re storing validation errors in the
session
too.

Let me know if this works,
Vish

Thank you Vish, that pointed me in the right direction…

Yes, I was storing the errors in the session. For now, I’ll just do a
“session[:order].errors.clear” in the appropriate place… I will fine
tune later.

Thanks again,
Chad