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"
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 :)
This post was a *serious* time saver for me. Thanks!