# map.root doesn't run controller logic?

**URL:** <https://discuss.rubyonrails.org/t/map-root-doesnt-run-controller-logic/35494>\
**Category:** rubyonrails-talk\
**Created:** [October 18, 2008, 10:50pm UTC](https://discuss.rubyonrails.org/t/map-root-doesnt-run-controller-logic/35494 "2008-10-18T22:50:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [October 18, 2008, 10:50pm UTC](https://discuss.rubyonrails.org/t/map-root-doesnt-run-controller-logic/35494/1 "2008-10-18T22: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:** ![Mauricio\_Linhares1](https://avatars.discourse-cdn.com/v4/letter/m/eada6e/32.png) [@Mauricio\_Linhares1](https://discuss.rubyonrails.org/u/Mauricio_Linhares1)\
**Post date:** [October 18, 2008, 11:07pm UTC](https://discuss.rubyonrails.org/t/map-root-doesnt-run-controller-logic/35494/2 "2008-10-18T23:07:35Z")

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

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [October 18, 2008, 11:14pm UTC](https://discuss.rubyonrails.org/t/map-root-doesnt-run-controller-logic/35494/3 "2008-10-18T23: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:** ![Mahmoud\_Said](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Mahmoud\_Said](https://discuss.rubyonrails.org/u/Mahmoud_Said)\
**Post date:** [October 19, 2008, 9:14am UTC](https://discuss.rubyonrails.org/t/map-root-doesnt-run-controller-logic/35494/4 "2008-10-19T09:14:00Z")

</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”

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [October 19, 2008, 10:08am UTC](https://discuss.rubyonrails.org/t/map-root-doesnt-run-controller-logic/35494/5 "2008-10-19T10: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 🙂
