rails routes

March 6, 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"

Comments

Daryn March 7, 2009

Hi Sarah, thanks for the kind comments on my Routing tutorial. Nice job on summarising some of the main points.

I have actually just returned from the hospital where I had an operation. Your comments have made my day :)

gabriel February 24, 2010

This post was a *serious* time saver for me. Thanks!