views:

345

answers:

5

I've been learning Rails but routes continues to confuse the heck out of me.

The thing that makes it most confusing, I think, is that the routes you define are sensitive to where they are defined in your routes.rb file relative to other routes.

Has anyone come across a nice simple guide that sums things up well?

+7  A: 

The first hit on Google for "Rails routes guide" is Rails Routing from the Outside In, which is quite comprehensive.

Jim Puls
Actually nearly all of the Rails Guides are very helpful!
molf
+1  A: 

http://guides.rubyonrails.org is a fantastic reference, and I found their guide on routing to be extremely helpful!

Barry Gallagher
+2  A: 

As a side remark:

The routes at the beginning take preference over the routes later in the file. So whenever you want to specify some kind of catchall route (like the default routes that map every action in every controller) you need to do that at the end.

nasmorn
+3  A: 

If you're okay with spending money on a dead tree reference, The Rails Way is actually worth it. The guides posted are probably your best bet this time, but if you plan on doing a lot of Rails, this book really breaks it down and makes it understandable. It's been a tremendous help for me. Good Luck.

Ben Hughes
Have you looked at many other Rails books or did you just kind of settle on that one?
planet
I've got the DHH written Agile Web Development with RoR book, ruby for rails (which is also a pretty crucial book), and the Rails Way. I've also looked at many of the other rails books at the bookstore. The only one that I keep at work is the Rails Way as it is the one I found myself using the most for reference.
Ben Hughes
+1  A: 

One thing to note when you are learning and experimenting with rails routes is that there is a way to see what rails is actually doing with your config/routes.rb file.

$rake routes

this will return all of the routes it has setup based upon your config/routes.rb file. This has been particularly helpful for me as I have learned about how all of the route variables names are setup, such as new_model1_model2_path(@model1).

Bryan Ward