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:

  • By default controllers render the view that has the same name of the action invoked.
  • index is the default action

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"

2 thoughts on “rails routes

  1. 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 :)

Leave a reply

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>