# Why we need routes.rb

**URL:** <https://www.ruby-forum.com/t/why-we-need-routes-rb/147799>\
**Category:** Rails\
**Created:** [September 5, 2008, 3:44pm UTC](https://www.ruby-forum.com/t/why-we-need-routes-rb/147799 "2008-09-05T15:44:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![palani](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed655f/32.png) [@palani](https://www.ruby-forum.com/u/palani)\
**Post date:** [September 5, 2008, 3:44pm UTC](https://www.ruby-forum.com/t/why-we-need-routes-rb/147799/1 "2008-09-05T15:44:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![palani](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed655f/32.png) [@palani](https://www.ruby-forum.com/u/palani)\
**Post date:** [September 5, 2008, 4:30pm UTC](https://www.ruby-forum.com/t/why-we-need-routes-rb/147799/2 "2008-09-05T16:30:50Z")

</div>

Take a look at  
[http://github.com/lifo/docrails/tree/master/railties/doc/guides/routing/routing\_outside\_in.txt](http://github.com/lifo/docrails/tree/master/railties/doc/guides/routing/routing_outside_in.txt)

---

<div class="post-metadata">

**Author:** ![palani](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed655f/32.png) [@palani](https://www.ruby-forum.com/u/palani)\
**Post date:** [September 5, 2008, 4:36pm UTC](https://www.ruby-forum.com/t/why-we-need-routes-rb/147799/3 "2008-09-05T16:36:07Z")

</div>

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

How do your application knows that [http://mysite.com/ticket](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  
action.

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.

Regards,  
Jorge Corona.

On Sep 5, 8:44 am, Palani K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
