Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added rake routes for listing all the defined routes in the system (c…

…loses #8795) [josh]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7149 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit f6a91b7b4ce2a7767392dfd3414a098047205c10 1 parent dfc15e1
@dhh dhh authored
Showing with 18 additions and 0 deletions.
  1. +2 −0  railties/CHANGELOG
  2. +16 −0 railties/lib/tasks/routes.rake
View
2  railties/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Added rake routes for listing all the defined routes in the system #8795 [josh]
+
* db:create creates the database for the current environment if it's on localhost. db:create:all creates local databases for all environments. #8783 [matt]
* Generators: look for generators in all gems, not just those suffixed with _generator, in the gem's generators or rails_generators directory. Allow use of the rails_generators directory instead of the standard generators directory in plugins also. #8730 [Dr Nic, topfunky]
View
16 railties/lib/tasks/routes.rake
@@ -0,0 +1,16 @@
+desc 'Print out all defined routes in match order, with names.'
+task :routes => :environment do
+ routes = ActionController::Routing::Routes.routes.collect do |route|
+ name = ActionController::Routing::Routes.named_routes.routes.index(route).to_s
+ verb = route.conditions[:method].to_s.upcase
+ segs = route.segments.inject("") { |str,s| str << s.to_s }
+ reqs = route.requirements.empty? ? "" : route.requirements.inspect
+ {:name => name, :verb => verb, :segs => segs, :reqs => reqs}
+ end
+ name_width = routes.collect {|r| r[:name]}.collect {|n| n.length}.max
+ verb_width = routes.collect {|r| r[:verb]}.collect {|v| v.length}.max
+ segs_width = routes.collect {|r| r[:segs]}.collect {|s| s.length}.max
+ routes.each do |r|
+ puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:segs].ljust(segs_width)} #{r[:reqs]}"
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.