Instance var getting lost during template render

hey all

I'm using rescue_from to catch exceptions and render a 'whoops - we had a problem' kind of page. Before i render the page, i set an instance variable @message which i want to use on the page. But, it's not being carried through for some reason - can anyone see why? Here's the setup i have:

  rescue_from Exception, :with => :any_exception   rescue_from ActionController::RoutingError, :with => :bad_url   rescue_from ActionController::MethodNotAllowed, :with => :bad_url   rescue_from ActionController::UnknownAction, :with => :bad_url

... private   def any_exception(exception)     @message = "We're sorry, but something went wrong."     render :template => "errors/index", :layout => "v4-2col-paranoid" and return   end

  def bad_url(exception)     @message = "I'm sorry, but this url is invalid. If you clicked on the url in an email, or copied it from somewhere, then please check that it was complete. If you got here by clicking on a link inside the site, then we apologise."     render :template => "errors/index", :layout => "v4-2col-paranoid" and return   end

So, i'm triggering the 'any_exception' method by putting <% raise "BOOM" %> in one of my views. I can see with logging that the any_exception method is called, and it does render the errors/index page. However, on the page, @message is nil - it's like it's got lost somewhere between being set and being used. Can anyone see what i'm doing wrong?

thanks, max

You should pass the variable with the locals parameter. render :template => "errors/index", :layout => "v4-2col-paranoid", :locals => {:message => @message}

And in the view, refer to it as message.

Hope it helps.

Leonardo Mateo wrote: