Skip to content

Instantly share code, notes, and snippets.

@ijcd
Created December 15, 2010 13:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ijcd/741931 to your computer and use it in GitHub Desktop.
Save ijcd/741931 to your computer and use it in GitHub Desktop.
# app/views/rescues/_trace.erb
<%
traces = [
["Application Trace", @exception.application_backtrace],
["Framework Trace", @exception.framework_backtrace],
["Full Trace", @exception.clean_backtrace]
]
names = traces.collect {|name, trace| name}
%>
<p><code>RAILS_ROOT: <%= defined?(RAILS_ROOT) ? RAILS_ROOT : "unset" %></code></p>
<div id="traces">
<% names.each do |name| %>
<%
show = "document.getElementById('#{name.gsub /\s/, '-'}').style.display='block';"
hide = (names - [name]).collect {|hide_name| "document.getElementById('#{hide_name.gsub /\s/, '-'}').style.display='none';"}
%>
<a href="#" onclick="<%= hide.join %><%= show %>; return false;"><%= name %></a> <%= '|' unless names.last == name %>
<% end %>
<% traces.each do |name, trace| %>
<div id="<%= name.gsub /\s/, '-' %>" style="display: <%= name == "Application Trace" ? 'block' : 'none' %>;">
<%
# Original code was:
# <pre><code><%=h trace.join "\n" %></code></pre>
%>
<pre><code><%= raw trace.join "<br/>\n" %></code></pre>
</div>
<% end %>
</div>
# app/controllers/application_controller.rb
#
# ALTERNATIVELY TO THE INITIALIZER BELOW, THIS WILL LET YOU DEBUG THE TEMPLATES
# AS IT WILL RELOAD WITH EACH REQUEST IN DEVELOPMENT
#
class ApplicationController < ActionController::Base
# Render detailed diagnostics for unhandled exceptions rescued from
# a controller action.
def rescue_action_locally(exception)
class << RESCUES_TEMPLATE_PATH
def [](path)
if Rails.root.join("app/views", path).exist?
ActionView::Template::EagerPath.new_and_loaded(Rails.root.join("app/views").to_s)[path]
else
super
end
end
end
super
end
end
# config/initializers/clickable_stacktrace.rb
#
# TO LOAD FUNCTIONALITY IN AN INITIALIZER
#
module ActionController
module Rescue
class << RESCUES_TEMPLATE_PATH
def [](path)
if Rails.root.join("app/views", path).exist?
ActionView::Template::EagerPath.new_and_loaded(Rails.root.join("app/views").to_s)[path]
else
super
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment