Howto verify the route of an URI in Rails?

So if you have an URI like this ‘/history/3’ and you want a quick way to figure out which controller or action that handle this routing, the normal and bad way is to go through the ‘config/routes.rb’ and work out the route. There is a better way:

$ ./script/console
Loading development environment.
>> irb ActionController::Routing::Routes
>> >> recognize_path(“/history/3”)
=> {:controller=>”auctions”, :action=>”history”, :id=>”3”}

You can past paramater :method into the recognize_path to verify route for method POST, GET, PUT and DELETE. For example, for POST:

recognize_path(“/history/3”, :method => :post)

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: