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

Comments

Leave a response

  1. AndrewJuly 02, 2007 @ 06:19 PM

    Why the semicolon in your routes?

  2. RobertJuly 03, 2007 @ 01:15 AM

    I believe it is because Ryan is not running on edge rails – probably 1.2.3.

  3. RobertJuly 03, 2007 @ 01:16 AM

    Or is that 1.2.1 – I can’t remember. :)

  4. Jarkko LaineJuly 03, 2007 @ 06:04 AM

    And if you’re not running on edge, you can use Sake to get the same listing: http://blog.hasmanythrough.com/2007/7/3/check-out-your-routes