Why we need routes.rb

Can anyone please explain me why we need routes.rb also explain the
basic idea abt routes.rb file.

Take a look at

routes.rb is the logical entry point of your application (the real
entry point is dispatch.rb, but that’s another story).
This file defines a map of URL templates and controller/actions to be

How do your application knows that http://mysite.com/ticket should go
to the Booking controller and run the show_tickets action?

You define a map on your routes.rb file. (in this example: map.connect
“ticket”, :controller => “Booking”, :action => “show_tickets”)
The URL fits the template “ticket”(the parameter just after
map.connect). This tells rails that when the URI /tickets fits the
pattern, it should instantiate the Booking controller and execute the
show tickets action.

At the very bottom of your routes.rb file is this map:

map.connect “:controller/:action/:id”

This is the default map. So if none of the previous templates on the
pattern fit, Rails tries to fit this last one.
This pattern means that if I have an URI like /ticket/show/3, it means
that it will instaniate the Ticket controller, execute the show action
and put :id => 3 on the params hash, so it can be accessed through the

So, as you see, this file is on the very heart of rails, and if
properly used, it can help you simplify greatly your application URLS.

Also is the most important file on RESTful applications, but thats
another big topic.

Jorge Corona.

On Sep 5, 8:44 am, Palani K. [email protected]