# :controller, how does Rails recognize them?

**URL:** <https://www.ruby-forum.com/t/controller-how-does-rails-recognize-them/191817>\
**Category:** Rails\
**Created:** [July 19, 2010, 11:21am UTC](https://www.ruby-forum.com/t/controller-how-does-rails-recognize-them/191817 "2010-07-19T11:21:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [July 19, 2010, 11:21am UTC](https://www.ruby-forum.com/t/controller-how-does-rails-recognize-them/191817/1 "2010-07-19T11:21:11Z")

</div>

In the Rails guides: [Getting Started with Rails — Ruby on Rails Guides](http://guides.rubyonrails.org/getting_started.html)

It mentions that we have the following in the “routes.rb” file:

map.connect ‘:controller/:action/:id’  
map.connect ‘:controller/:action/:id.:format’

Now, in completing the tutorial, we will add the following to  
“routes.rb”:

map.root :controller =\> “home”

In the first two statements we have :controller, and in the last  
statement, we have a :controller pointing to a value.

How does Rails determine that the first two statements point to a  
:controller other than the last statement?

And, in the last statement, what are we exactly saying?

Thanks.

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [July 19, 2010, 11:26am UTC](https://www.ruby-forum.com/t/controller-how-does-rails-recognize-them/191817/2 "2010-07-19T11:26:29Z")

</div>

For, map.root :controller =\> “home”, I noticed that .root is a method  
that tells Rails that this route is applied to requests made for the  
root of the site.

> **[Rails Routing from the Outside In — Ruby on Rails Guides](https://guides.rubyonrails.org/routing.html)**
>
> Rails Routing from the Outside InThis guide covers the user-facing features of Rails routing.After reading this guide, you will know: How to interpret the code in config/routes.rb. How to construct your own routes, using either the preferred...

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [July 19, 2010, 11:29am UTC](https://www.ruby-forum.com/t/controller-how-does-rails-recognize-them/191817/3 "2010-07-19T11:29:25Z")

</div>

> In the first two statements we have :controller, and in the last  
> statement, we have a :controller pointing to a value.
> 
> How does Rails determine that the first two statements point to a  
> :controller other than the last statement?

Because it’s mapping a URL pattern to a controller and action. For  
example,  
it means that:

[http://www.example.com/users](http://www.example.com/users)

Will go to the UsersController’s index action (because index is the  
default  
action) with no id (as nil is the default for a missing parameter at the  
end).

[http://www.example.com/users/show/1](http://www.example.com/users/show/1)

Will map to the show actions of UsersController passing in a params[:id]  
of  
1.

And, in the last statement, what are we exactly saying?

> 

That the / ([http://www.example.com/](http://www.example.com/)) should go to the HomeController  
class’s  
index action (as index is the default as above).

Cheers,

Andy

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [July 19, 2010, 11:43am UTC](https://www.ruby-forum.com/t/controller-how-does-rails-recognize-them/191817/4 "2010-07-19T11:43:18Z")

</div>

Thanks Andy.
