rails routes

March 07, 2009

I just went through a fabulous tutorial by Daryn Holmes about routes. It is written for 2.0.2, but I found that nothing had changed for 2.2. I already had a good feel for how routes worked, but stepping through the details was very helpful.

Key points:

Debugging Tips:
You can quickly see where a route ends up by typing this into irb:


>> rts = ActionController::Routing::Routes
>> rts.recognize_path("/")
=> {:controller=>"albums", :action=>"index"}

You can also go in the reverse direction to see what URL would be generated by a route. To see what URL an action will end up at:


>> rts.generate(:controller=>'albums',:action=>'index')
=> "/music"