mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
/rails/info/routes path shows routing information
Will show similar contents to the output of `$ rake routes` in the browser in development. This speeds the time required to generate routes, since the application is already initialized.
This commit is contained in:
parent
abccf82c8b
commit
cb44e0fed9
7 changed files with 72 additions and 8 deletions
|
@ -1,5 +1,7 @@
|
|||
## Rails 4.0.0 (unreleased) ##
|
||||
|
||||
* Add `/rails/info/routes` path, displays same information as `rake routes` *Richard Schneeman & Andrew White*
|
||||
|
||||
* Improved `rake routes` output for redirects *Łukasz Strzałkowski & Andrew White*
|
||||
|
||||
* Load all environments available in `config.paths["config/environments"]`. *Piotr Sarnacki*
|
||||
|
|
|
@ -23,6 +23,8 @@ module Rails
|
|||
if Rails.env.development?
|
||||
app.routes.append do
|
||||
get '/rails/info/properties' => "rails/info#properties"
|
||||
get '/rails/info/routes' => "rails/info#routes"
|
||||
get '/rails/info' => "rails/info#index"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -51,7 +51,7 @@ module Rails
|
|||
end
|
||||
|
||||
def internal?
|
||||
path =~ %r{/rails/info/properties|^#{Rails.application.config.assets.prefix}}
|
||||
path =~ %r{/rails/info.*|^#{Rails.application.config.assets.prefix}}
|
||||
end
|
||||
|
||||
def engine?
|
||||
|
|
|
@ -1,15 +1,33 @@
|
|||
require 'rails/application/route_inspector'
|
||||
|
||||
class Rails::InfoController < ActionController::Base
|
||||
self.view_paths = File.join(File.dirname(__FILE__), 'templates')
|
||||
layout 'application'
|
||||
|
||||
before_filter :require_local!
|
||||
|
||||
def index
|
||||
redirect_to '/rails/info/routes'
|
||||
end
|
||||
|
||||
def properties
|
||||
if consider_all_requests_local? || request.local?
|
||||
render :inline => Rails::Info.to_html
|
||||
else
|
||||
render :text => '<p>For security purposes, this information is only available to local requests.</p>', :status => :forbidden
|
||||
end
|
||||
@info = Rails::Info.to_html
|
||||
end
|
||||
|
||||
def routes
|
||||
inspector = Rails::Application::RouteInspector.new
|
||||
@info = inspector.format(_routes.routes).join("\n")
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def consider_all_requests_local?
|
||||
Rails.application.config.consider_all_requests_local
|
||||
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
|
||||
|
|
32
railties/lib/rails/templates/layouts/application.html.erb
Normal file
32
railties/lib/rails/templates/layouts/application.html.erb
Normal file
|
@ -0,0 +1,32 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Routes</title>
|
||||
<style>
|
||||
body { background-color: #fff; color: #333; }
|
||||
|
||||
body, p, ol, ul, td {
|
||||
font-family: helvetica, verdana, arial, sans-serif;
|
||||
font-size: 13px;
|
||||
line-height: 18px;
|
||||
}
|
||||
|
||||
pre {
|
||||
background-color: #eee;
|
||||
padding: 10px;
|
||||
font-size: 11px;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
a { color: #000; }
|
||||
a:visited { color: #666; }
|
||||
a:hover { color: #fff; background-color:#000; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Your App: <%= link_to 'properties', '/rails/info/properties' %> | <%= link_to 'routes', '/rails/info/routes' %></h2>
|
||||
<%= yield %>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1 @@
|
|||
<%= @info.html_safe %>
|
9
railties/lib/rails/templates/rails/info/routes.html.erb
Normal file
9
railties/lib/rails/templates/rails/info/routes.html.erb
Normal file
|
@ -0,0 +1,9 @@
|
|||
<h2>
|
||||
Routes
|
||||
</h2>
|
||||
|
||||
<p>
|
||||
Routes match in priority from top to bottom
|
||||
</p>
|
||||
|
||||
<p><pre><%= @info %></pre></p>
|
Loading…
Reference in a new issue