# Map.root doesn't run controller logic?

**URL:** <https://www.ruby-forum.com/t/map-root-doesnt-run-controller-logic/151263>\
**Category:** Rails\
**Created:** [October 19, 2008, 12:50am UTC](https://www.ruby-forum.com/t/map-root-doesnt-run-controller-logic/151263 "2008-10-19T00:50:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisjo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a183cd/32.png) [@chrisjo](https://www.ruby-forum.com/u/chrisjo)\
**Post date:** [October 19, 2008, 12:50am UTC](https://www.ruby-forum.com/t/map-root-doesnt-run-controller-logic/151263/1 "2008-10-19T00:50:50Z")

</div>

I have this in my routes.rb:

map.resources :events

# …

map.root :controller =\> “events”, :action =\> :index

Surely enough, accessing [http://localhost:3000/](http://localhost:3000/) renders the  
events/index.html.erb template. However, accessing  
[http://localhost:3000/events](http://localhost:3000/events) renders the same page/template slightly  
different, as the controller logic (EventsController#index) loads some  
objects that’s not available at “/”. Apparently the root route doesn’t  
run the controller logic at all - it only renders the template.

Is there something wrong here, or am I the one with wrong expectations?  
How can I fix it?

---

<div class="post-metadata">

**Author:** ![chrisjo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a183cd/32.png) [@chrisjo](https://www.ruby-forum.com/u/chrisjo)\
**Post date:** [October 19, 2008, 1:08am UTC](https://www.ruby-forum.com/t/map-root-doesnt-run-controller-logic/151263/2 "2008-10-19T01:08:27Z")

</div>

Try to change the mapping to:

map.root :controller =\> “events”, :action =\> “index”

The root route does run the controller logic, maybe there is something  
mistyped in your routes.rb file.

On Sat, Oct 18, 2008 at 7:50 PM, Christian J.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> different, as the controller logic (EventsController#index) loads some  
> objects that’s not available at “/”. Apparently the root route doesn’t  
> run the controller logic at all - it only renders the template.
> 
> ## Is there something wrong here, or am I the one with wrong expectations? How can I fix it?
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Maurício Linhares  
[http://alinhavado.wordpress.com/](http://alinhavado.wordpress.com/) (pt-br) | [http://blog.codevader.com/](http://blog.codevader.com/)  
(en)  
João Pessoa, PB, +55 83 8867-7208

---

<div class="post-metadata">

**Author:** ![chrisjo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a183cd/32.png) [@chrisjo](https://www.ruby-forum.com/u/chrisjo)\
**Post date:** [October 19, 2008, 1:14am UTC](https://www.ruby-forum.com/t/map-root-doesnt-run-controller-logic/151263/3 "2008-10-19T01:14:30Z")

</div>

Yup, specifying the action as a string fixed it. Strange that the action  
name as symbol mapping would find the right template, but not the right  
controller action. Oh, well, guess I’m not supposed to do that anyway 🙂

---

<div class="post-metadata">

**Author:** ![chrisjo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a183cd/32.png) [@chrisjo](https://www.ruby-forum.com/u/chrisjo)\
**Post date:** [October 19, 2008, 11:14am UTC](https://www.ruby-forum.com/t/map-root-doesnt-run-controller-logic/151263/4 "2008-10-19T11:14:58Z")

</div>

I find this very strange actually…

what version of rails u r on??

what happens if u just specified the controller in the mapping (with no  
action at all)… the index is the default action anyway…

try  
map.root :controller =\> “events”

On Sun, Oct 19, 2008 at 1:14 AM, Christian J. \<  
removed\_email\_address@domain.invalid\> wrote:

> ## Yup, specifying the action as a string fixed it. Strange that the action name as symbol mapping would find the right template, but not the right controller action. Oh, well, guess I’m not supposed to do that anyway 🙂
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Mahmoud Said  
Software Developer

> **[Thoughts](http://blog.modsaid.com)**

www.eSpace.com.eg  
+20-16-1223857

---

<div class="post-metadata">

**Author:** ![chrisjo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a183cd/32.png) [@chrisjo](https://www.ruby-forum.com/u/chrisjo)\
**Post date:** [October 19, 2008, 12:08pm UTC](https://www.ruby-forum.com/t/map-root-doesnt-run-controller-logic/151263/5 "2008-10-19T12:08:36Z")

</div>

mahmoud said wrote:

> I find this very strange actually…
> 
> what version of rails u r on??

2.1

> what happens if u just specified the controller in the mapping (with no  
> action at all)… the index is the default action anyway…

That also works. Guess we all learned somthing new then 🙂
