Howto dump Rails routes?

The easiest way to dump all the routes out to the screen is with the Rake task ‘routes’:

$ rake routes

OR if you can dump it within the Rails console

$ ruby script/console
ruby-1.8.7-p249 > rs = ActionController::Routing::Routes
ruby-1.8.7-p249 > puts rs.routes

rs is object of class ActionController::Routing::RouteSet which consist of an Array of ActionController::Routing::Route objects.

Then how to test the output of a named route?

$ ruby script/console
ruby-1.8.7-p249 > # app.<named routes>
ruby-1.8.7-p249 > # assume you have the posts_path
ruby-1.8.7-p249 > app.posts_path
=> "/posts"

Hope you find this tip handy 🙂

Advertisements

About Jones Lee

Nothing much about me..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: