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.

ATP Railties
---
railties/CHANGELOG.md | 4 ++
railties/lib/rails/info_controller.rb | 3 +-
.../lib/rails/templates/rails/info/routes.html.erb | 75 +++++++++++++++++++++-
railties/test/rails_info_controller_test.rb | 2 +-
4 files changed, 80 insertions(+), 4 deletions(-)
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index ed5dfc6446..126a38a2d6 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,5 +1,9 @@
## Rails 4.0.0 (unreleased) ##
+* The `rails/info/routes` now correctly formats routing output as an html table.
+
+ *Richard Schneeman*
+
* The `public/index.html` is no longer generated for new projects.
Page is replaced by internal `welcome_controller` inside of railties.
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
+
+
+
+
+
+ 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 Verb |
+ Path |
+ Controller#Action |
+
+
+
+ <% @routes.each do |route| %>
+
+
+ <% if route[:name].present? %>
+ <%= route[:name] %>_path
+ <% end %>
+ |
+
+ <%= route[:verb] %>
+ |
+
+ <%= route[:path] %>
+ |
+
+ <%= route[:reqs] %>
+ |
+
+ <% end %>
+
+
+
+
diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb
index 08fcddd4bf..a9b237d0a5 100644
--- a/railties/test/rails_info_controller_test.rb
+++ b/railties/test/rails_info_controller_test.rb
@@ -50,7 +50,7 @@ class InfoControllerTest < ActionController::TestCase
test "info controller renders with routes" do
get :routes
- assert_select 'pre'
+ assert_response :success
end
end
--
cgit v1.2.3