What's New in Edge Rails: Use Rake to List Your Routes

Posted by ryan
at 4:59 PM on Monday, July 02, 2007



While you’ve always been able to manually take a peek at what routes are defined in your application, this dollop of usefulness has now found its way into a rake task.

Just run


rake routes

and voila, all routes defined will be spit out in a tidy columnar form with the following columns:

route name, HTTP method, route path, route requirements

As an example, here is what my output looks like:

1
2
   all_articles GET  /articles;all/      {:action=>"all", :controller=>"articles"}
search_articles GET  /articles;search/   {:action=>"search", :controller=>"articles"}
For those of us not riding edge, it’s pretty easy to get access to this task in your app:

curl http://svn.rubyonrails.org/rails/trunk/railties/lib/tasks/routes.rake > lib/tasks/routes.rake

This is particularly useful in RESTful implementations as there’s lot of routing magic happening for you under the covers. Now you have the means to take a harmless peek under said covers.

tags: ruby, rubyonrails, rake