rails routes

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"
This entry was posted in code. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. Posted March 7, 2009 at 12:29 pm | Permalink

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

  2. gabriel
    Posted February 24, 2010 at 10:55 pm | Permalink

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

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*