# Controller#index is getting called immediately after every single other call

**URL:** <https://www.ruby-forum.com/t/controller-index-is-getting-called-immediately-after-every-single-other-call/141746>\
**Category:** Rails\
**Created:** [June 30, 2008, 9:50am UTC](https://www.ruby-forum.com/t/controller-index-is-getting-called-immediately-after-every-single-other-call/141746 "2008-06-30T09:50:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bret\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b782af/32.png) [@Bret\_H](https://www.ruby-forum.com/u/Bret_H)\
**Post date:** [June 30, 2008, 9:50am UTC](https://www.ruby-forum.com/t/controller-index-is-getting-called-immediately-after-every-single-other-call/141746/1 "2008-06-30T09:50:23Z")

</div>

This is a very odd problem, it’s been happening, I think, ever since I  
patched to Rails 2.1.0

Every time a public method gets called in my Controller, the index  
method gets called immediately afterwards. It’s not in my code, and my  
best guess after testing it on two pretty different machines is, it’s  
not my browser settings either. My cookies and sessions seem to be  
working fine, DB isn’t behaving oddly.

In absence of a direct answer, I’m wondering if someone can tell me  
how to get Rails Logger (or equivalent) to spit out a complete  
stacktrace. I’m sure if I could just see where the heck that call is  
coming from, I could solve the rest of it.

Thanks very much,

Bret

---

<div class="post-metadata">

**Author:** ![Bret\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b782af/32.png) [@Bret\_H](https://www.ruby-forum.com/u/Bret_H)\
**Post date:** [June 30, 2008, 11:48am UTC](https://www.ruby-forum.com/t/controller-index-is-getting-called-immediately-after-every-single-other-call/141746/2 "2008-06-30T11:48:48Z")

</div>

Bret H wrote:

> This is a very odd problem, it’s been happening, I think, ever since I  
> patched to Rails 2.1.0
> 
> In absence of a direct answer, I’m wondering if someone can tell me  
> how to get Rails Logger (or equivalent) to spit out a complete  
> stacktrace. I’m sure if I could just see where the heck that call is  
> coming from, I could solve the rest of it.
> 
> Thanks very much,
> 
> Bret

You should find your logs at /log in your rails app folder. There should  
be 3 files, one for each environment mode (test / dev / prod), they are  
automatically filled up with request information.

Guillaume Petit

---

<div class="post-metadata">

**Author:** ![Bret\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b782af/32.png) [@Bret\_H](https://www.ruby-forum.com/u/Bret_H)\
**Post date:** [June 30, 2008, 3:04pm UTC](https://www.ruby-forum.com/t/controller-index-is-getting-called-immediately-after-every-single-other-call/141746/3 "2008-06-30T15:04:44Z")

</div>

Hi, thanks for the suggestion… my experience so far is that  
information only gets written to the log when I write it explicitly  
with a call like

Logger.debug(“sometext”)

I’m not sure how I could capture the information I need given this  
limitation. Any ideas?

---

<div class="post-metadata">

**Author:** ![Bret\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b782af/32.png) [@Bret\_H](https://www.ruby-forum.com/u/Bret_H)\
**Post date:** [July 1, 2008, 8:37am UTC](https://www.ruby-forum.com/t/controller-index-is-getting-called-immediately-after-every-single-other-call/141746/4 "2008-07-01T08:37:33Z")

</div>

Ah, well I solved my problem. The method I needed is  
Kernel.caller(start=1)… returns a series of strings roughly  
approximating a stacktrace starting with the scope in which caller is  
called.

Thanks for taking the time, though, Guillaume,

Bret

---

<div class="post-metadata">

**Author:** ![Bret\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b782af/32.png) [@Bret\_H](https://www.ruby-forum.com/u/Bret_H)\
**Post date:** [June 30, 2008, 6:21pm UTC](https://www.ruby-forum.com/t/controller-index-is-getting-called-immediately-after-every-single-other-call/141746/5 "2008-06-30T18:21:08Z")

</div>

Well you got it right 🙂

Every controller in rails has a logger _automatically_ instanciated for  
them.

Simply use the logger.info(“information to log”), (or .debug, .warn, etc  
…) like you used to in other language to log more information. It’s a  
lowercase “l”

Since we are in logging, try to call the method .inspect on any object  
you wish to look at, that will produce a nice string with your object  
information, very handy when it comes to logging 🙂

I don’t know much in logging with rails, but so far, that was more than  
enough 🙂

Guillaume Petit
