Changing the rendering for displaying exceptions

I just added autofresh support for the stacktrace pages, now you get get the benefits of autofresh while you are refactoring your code, which can cause temporary breakage, for example. It was easy, altough not at first easy to find. The answer was found in the comments of actionpack/lib/action_controller/rescue.rb. It bascially said you just need to override the rescue_action_in_public - for "public" errors - and rescue_action_locally - for local errors, which shows the stacktraces. I just copied the existing rescue_action_locally method over and swapped in my template file instead(changed code in orange):

module ActionController
  class Base
    def rescue_action_locally(exception)
      render :text => 'it bombed'
      add_variables_to_assigns
      @template.instance_variable_set("@exception", exception)
      @template.instance_variable_set("@rescues_path", File.dirname(rescues_path("stub")))
      @template.send!(:assign_variables_from_controller)
 
      @template.instance_variable_set("@contents", @template.render_file(template_path_for_local_rescue(exception), false))
 
      response.content_type = Mime::HTML
      render_for_file("#{File.dirname(__FILE__)}/templates/layout.erb", response_code_for_rescue(exception))
    end
  end
end

This will tell it to find the layout.erb in my plugin directory instead of the one buried deep inside rails.

blog comments powered by Disqus