Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best guide to Rails routes for the totally confused?

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?

like image 723
planet Avatar asked Jun 23 '09 22:06

planet


People also ask

How do I see all Rails routes?

TIP: If you ever want to list all the routes of your application you can use rails routes on your terminal and if you want to list routes of a specific resource, you can use rails routes | grep hotel . This will list all the routes of Hotel.

What are resourceful routes Rails?

Resource routing allows you to quickly declare all of the common routes for a given resourceful controller. A single call to resources can declare all of the necessary routes for your index , show , new , edit , create , update , and destroy actions.

What does as do in Rails routes?

The :as option creates a named path. You can then call this path in your controllers and views (e.g. redirect_to things_path ).

What is RESTful route in Rails?

In Rails, a RESTful route provides a mapping between HTTP verbs, controller actions, and (implicitly) CRUD operations in a database. A single entry in the routing file, such as. map.resources :photos. creates seven different routes in your application: HTTP verb.


3 Answers

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

like image 104
Jim Puls Avatar answered Nov 08 '22 06:11

Jim Puls


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.

like image 29
Ben Hughes Avatar answered Nov 08 '22 07:11

Ben Hughes


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.

like image 33
nasmorn Avatar answered Nov 08 '22 06:11

nasmorn