From 8a59b873749a88b0f4ed9b80bc3237c88313302c Mon Sep 17 00:00:00 2001 From: schneems Date: Sat, 15 Dec 2012 11:36:26 -0600 Subject: HTML formatting to Rails::InfoController#routes This PR adds formatting and meta-data to the display of the internal routes. Users can now toggle between showing helpers with the `_path` or _`url` suffix. There are multiple ways to achieve this, this method uses partials for formatting and meta-data. The partials can be re-used when rendering `routing_error.erb`, though that will need to be in a separate PR. ![](http://f.cl.ly/items/3A2p3c1T1t2f2X2R2K2S/Screen%20Shot%202012-12-12%20at%202.28.01%20PM.png) ATP Railties --- railties/lib/rails/info_controller.rb | 3 +- .../lib/rails/templates/rails/info/routes.html.erb | 75 +++++++++++++++++++++- 2 files changed, 75 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/info_controller.rb b/railties/lib/rails/info_controller.rb index e296637f39..ec7d5ed610 100644 --- a/railties/lib/rails/info_controller.rb +++ b/railties/lib/rails/info_controller.rb @@ -15,8 +15,7 @@ class Rails::InfoController < ActionController::Base # :nodoc: end def routes - inspector = ActionDispatch::Routing::RoutesInspector.new - @info = inspector.format(_routes.routes).join("\n") + @routes = ActionDispatch::Routing::RoutesInspector.new.collect_routes(_routes.routes) end protected diff --git a/railties/lib/rails/templates/rails/info/routes.html.erb b/railties/lib/rails/templates/rails/info/routes.html.erb index 890f6f5b03..e34c1c4135 100644 --- a/railties/lib/rails/templates/rails/info/routes.html.erb +++ b/railties/lib/rails/templates/rails/info/routes.html.erb @@ -6,4 +6,77 @@ Routes match in priority from top to bottom

-

<%= @info %>

\ No newline at end of file + + + + + + + + + + + + + <% @routes.each do |route| %> + + + + + + + <% end %> + +
Helper
+ <%= link_to "Path", "#", 'data-route-helper' => '_path', + title: "Returns a relative path (without the http or domain)" %> / + <%= link_to "Url", "#", 'data-route-helper' => '_url', + title: "Returns an absolute url (with the http and domain)" %> +
HTTP VerbPathController#Action
+ <% if route[:name].present? %> + <%= route[:name] %>_path + <% end %> + + <%= route[:verb] %> + + <%= route[:path] %> + + <%= route[:reqs] %> +
+ + -- cgit v1.2.3 From 37d9c44b6d15cc0b02f327fe51687db7d0443bb8 Mon Sep 17 00:00:00 2001 From: schneems Date: Mon, 17 Dec 2012 14:26:46 -0600 Subject: Format routes as html on debug page 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.
![](http://f.cl.ly/items/3O1D0K1v0j0i343O3T3T/Screen%20Shot%202012-12-17%20at%203.07.20%20PM.png) --- railties/lib/rails/info_controller.rb | 1 + .../lib/rails/templates/rails/info/routes.html.erb | 78 ++-------------------- 2 files changed, 5 insertions(+), 74 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/info_controller.rb b/railties/lib/rails/info_controller.rb index ec7d5ed610..e650f58d20 100644 --- a/railties/lib/rails/info_controller.rb +++ b/railties/lib/rails/info_controller.rb @@ -2,6 +2,7 @@ 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! diff --git a/railties/lib/rails/templates/rails/info/routes.html.erb b/railties/lib/rails/templates/rails/info/routes.html.erb index e34c1c4135..1ea387c63f 100644 --- a/railties/lib/rails/templates/rails/info/routes.html.erb +++ b/railties/lib/rails/templates/rails/info/routes.html.erb @@ -6,77 +6,7 @@ Routes match in priority from top to bottom

- - - - - - - - - - - - - <% @routes.each do |route| %> - - - - - - - <% end %> - -
Helper
- <%= link_to "Path", "#", 'data-route-helper' => '_path', - title: "Returns a relative path (without the http or domain)" %> / - <%= link_to "Url", "#", 'data-route-helper' => '_url', - title: "Returns an absolute url (with the http and domain)" %> -
HTTP VerbPathController#Action
- <% if route[:name].present? %> - <%= route[:name] %>_path - <% end %> - - <%= route[:verb] %> - - <%= route[:path] %> - - <%= route[:reqs] %> -
- - +<%# actionpack/lib/action_dispatch/middleware/templates %> +<%= render layout: "routes/route_wrapper" do %> + <%= render partial: "routes/route", collection: @routes %> +<% end %> -- cgit v1.2.3