aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
diff options
context:
space:
mode:
authorschneems <richard.schneeman@gmail.com>2012-06-09 14:54:49 -0500
committerschneems <richard.schneeman@gmail.com>2012-07-07 15:38:29 -0500
commitfa714ec7dffd12b8508c756e6526eff5ae8e4202 (patch)
tree4a1307d0ae5ac6af0ee40a3c8f8fc118535cdb78 /actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
parentee20be7c33538e6e9d334ddbd16d427190c7ff00 (diff)
downloadrails-fa714ec7dffd12b8508c756e6526eff5ae8e4202.tar.gz
rails-fa714ec7dffd12b8508c756e6526eff5ae8e4202.tar.bz2
rails-fa714ec7dffd12b8508c756e6526eff5ae8e4202.zip
show routes while debugging RoutingError
If someone receives a routing error, they likely need to view the routes. Rather than making them visit '/rails/info/routes' or run `rake routes` we can give them that information on the page.
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware/debug_exceptions.rb')
-rw-r--r--actionpack/lib/action_dispatch/middleware/debug_exceptions.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
index b903f98761..467437b512 100644
--- a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
+++ b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
@@ -1,5 +1,7 @@
require 'action_dispatch/http/request'
require 'action_dispatch/middleware/exception_wrapper'
+require 'rails/application/route_inspector'
+
module ActionDispatch
# This middleware is responsible for logging exceptions and
@@ -39,7 +41,8 @@ module ActionDispatch
:exception => wrapper.exception,
:application_trace => wrapper.application_trace,
:framework_trace => wrapper.framework_trace,
- :full_trace => wrapper.full_trace
+ :full_trace => wrapper.full_trace,
+ :routes => formatted_routes(exception)
)
file = "rescues/#{wrapper.rescue_template}"
@@ -78,5 +81,13 @@ module ActionDispatch
def stderr_logger
@stderr_logger ||= ActiveSupport::Logger.new($stderr)
end
+
+ private
+ def formatted_routes(exception)
+ if exception.is_a?(ActionController::RoutingError) || exception.is_a?(ActionView::Template::Error)
+ inspector = Rails::Application::RouteInspector.new
+ inspector.format(Rails.application.routes.routes).join("\n")
+ end
+ end
end
end