Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

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.

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

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

I just used the one at rubyonrails.org. With all the links, it's a good one..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top