mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
37d9c44b6d
When someone gets a routing exception, the routes are rendered (starting in Rails 4.0). This PR brings parity between the html routes in the `rails/info/routes` path and when rendered from an exception. This is the continuation of #8521 which brought html formatted routes. In addition to bringing parity to the two views, we're keeping our views DRY by rendering off of the same partials. In this case Railties depends on partials provided by ActionDispatch. I'm open to alternative implementations. Ideally both views will use the same code so any improvements or updates to it will be reproduced on both. <hr /> ![](http://f.cl.ly/items/3O1D0K1v0j0i343O3T3T/Screen%20Shot%202012-12-17%20at%203.07.20%20PM.png)
33 lines
831 B
Ruby
33 lines
831 B
Ruby
require 'action_dispatch/routing/inspector'
|
|
|
|
class Rails::InfoController < ActionController::Base # :nodoc:
|
|
self.view_paths = File.expand_path('../templates', __FILE__)
|
|
prepend_view_path ActionDispatch::DebugExceptions::RESCUES_TEMPLATE_PATH
|
|
layout 'application'
|
|
|
|
before_filter :require_local!
|
|
|
|
def index
|
|
redirect_to '/rails/info/routes'
|
|
end
|
|
|
|
def properties
|
|
@info = Rails::Info.to_html
|
|
end
|
|
|
|
def routes
|
|
@routes = ActionDispatch::Routing::RoutesInspector.new.collect_routes(_routes.routes)
|
|
end
|
|
|
|
protected
|
|
|
|
def require_local!
|
|
unless local_request?
|
|
render text: '<p>For security purposes, this information is only available to local requests.</p>', status: :forbidden
|
|
end
|
|
end
|
|
|
|
def local_request?
|
|
Rails.application.config.consider_all_requests_local || request.local?
|
|
end
|
|
end
|