From cb44e0fed97d7cef024e9dd9cc113a75cc7d6f20 Mon Sep 17 00:00:00 2001 From: schneems Date: Tue, 22 May 2012 18:23:17 -0500 Subject: /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. --- railties/CHANGELOG.md | 2 ++ railties/lib/rails/application/finisher.rb | 2 ++ railties/lib/rails/application/route_inspector.rb | 2 +- railties/lib/rails/info_controller.rb | 32 +++++++++++++++++----- .../rails/templates/layouts/application.html.erb | 32 ++++++++++++++++++++++ .../rails/templates/rails/info/properties.html.erb | 1 + .../lib/rails/templates/rails/info/routes.html.erb | 9 ++++++ 7 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 railties/lib/rails/templates/layouts/application.html.erb create mode 100644 railties/lib/rails/templates/rails/info/properties.html.erb create mode 100644 railties/lib/rails/templates/rails/info/routes.html.erb (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index ccccc178c5..787bafea04 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -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* diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 84f2601f28..60aa40b92f 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -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 diff --git a/railties/lib/rails/application/route_inspector.rb b/railties/lib/rails/application/route_inspector.rb index b23fb3e920..942c4f4789 100644 --- a/railties/lib/rails/application/route_inspector.rb +++ b/railties/lib/rails/application/route_inspector.rb @@ -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? diff --git a/railties/lib/rails/info_controller.rb b/railties/lib/rails/info_controller.rb index 6b4bdb2921..5081074395 100644 --- a/railties/lib/rails/info_controller.rb +++ b/railties/lib/rails/info_controller.rb @@ -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 => '

For security purposes, this information is only available to local requests.

', :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 => '

For security purposes, this information is only available to local requests.

', :status => :forbidden + end + end + + def local_request? + Rails.application.config.consider_all_requests_local || request.local? end end diff --git a/railties/lib/rails/templates/layouts/application.html.erb b/railties/lib/rails/templates/layouts/application.html.erb new file mode 100644 index 0000000000..53276d3e7c --- /dev/null +++ b/railties/lib/rails/templates/layouts/application.html.erb @@ -0,0 +1,32 @@ + + + + + Routes + + + +

Your App: <%= link_to 'properties', '/rails/info/properties' %> | <%= link_to 'routes', '/rails/info/routes' %>

+<%= yield %> + + + diff --git a/railties/lib/rails/templates/rails/info/properties.html.erb b/railties/lib/rails/templates/rails/info/properties.html.erb new file mode 100644 index 0000000000..d47cbab202 --- /dev/null +++ b/railties/lib/rails/templates/rails/info/properties.html.erb @@ -0,0 +1 @@ +<%= @info.html_safe %> \ No newline at end of file diff --git a/railties/lib/rails/templates/rails/info/routes.html.erb b/railties/lib/rails/templates/rails/info/routes.html.erb new file mode 100644 index 0000000000..890f6f5b03 --- /dev/null +++ b/railties/lib/rails/templates/rails/info/routes.html.erb @@ -0,0 +1,9 @@ +

+ Routes +

+ +

+ Routes match in priority from top to bottom +

+ +

<%= @info %>

\ No newline at end of file -- cgit v1.2.3