# HowTo: Display file being executed?

**URL:** <https://www.ruby-forum.com/t/howto-display-file-being-executed/120839>\
**Category:** Rails\
**Created:** [November 21, 2007, 12:53am UTC](https://www.ruby-forum.com/t/howto-display-file-being-executed/120839 "2007-11-21T00:53:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![drub](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e56c9b/32.png) [@drub](https://www.ruby-forum.com/u/drub)\
**Post date:** [November 21, 2007, 12:53am UTC](https://www.ruby-forum.com/t/howto-display-file-being-executed/120839/1 "2007-11-21T00:53:27Z")

</div>

Would like to display some debug code, the file being executed.

I want to see something like “File: app/views/site/file.rhtml”

Have tried displaying **FILE** and get a consistent string, regardless  
of the page displayed. That is  
“script/…/config/…/app/views/layouts/application.rhtml”

Have tried $0 which displays a consistent string, “script/server”.

Is there another variable, or another technique, to display the file  
names I desire? e.g. /app/views//

I’m new to ROR. Thank go to the Rails Space book!

Many thanks!

---

<div class="post-metadata">

**Author:** ![drub](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e56c9b/32.png) [@drub](https://www.ruby-forum.com/u/drub)\
**Post date:** [November 21, 2007, 8:25am UTC](https://www.ruby-forum.com/t/howto-display-file-being-executed/120839/2 "2007-11-21T08:25:14Z")

</div>

Drub Drub wrote:

> Would like to display some debug code, the file being executed.
> 
> I want to see something like “File: app/views/site/file.rhtml”
> 
> Have tried displaying **FILE** and get a consistent string, regardless  
> of the page displayed. That is  
> “script/…/config/…/app/views/layouts/application.rhtml”
> 
> Have tried $0 which displays a consistent string, “script/server”.
> 
> Is there another variable, or another technique, to display the file  
> names I desire? e.g. /app/views//
> 
> I’m new to ROR. Thank go to the Rails Space book!
> 
> Many thanks!

I am not sure if this will do it, but off the top of my head I would say  
have a look in the params hash. Everytime an action is called, I think  
the controller and action are pushed into the params hash.

This only works assuming that you are rendering a template for each  
action and the template has the same name as the action (you would have  
had to have overridden that behaviour).

Try accessing params[:controller] and params[:action]. If that works,  
then the file will be found at  
/app/views/params[:controller]/params[:action]

(Extensions will not be included)

---

<div class="post-metadata">

**Author:** ![drub](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e56c9b/32.png) [@drub](https://www.ruby-forum.com/u/drub)\
**Post date:** [November 21, 2007, 8:57pm UTC](https://www.ruby-forum.com/t/howto-display-file-being-executed/120839/3 "2007-11-21T20:57:15Z")

</div>

Many thanks, ce bi. Ya got me thinking in the right direction. Bravo.

I found that

\<%= debug(params) %\>

works quite nicely. You’re right, params contains both the the action  
and the controller. This line displays both.

Just what was needed.  
Now, on to the next stumbling stone. 😉  
Feel like I’m trying to drink from a fire hose!

Drub

ce bi wrote:

> Drub Drub wrote:
> 
> > Would like to display some debug code, the file being executed.
> > 
> > I want to see something like “File: app/views/site/file.rhtml”
> > 
> > Have tried displaying **FILE** and get a consistent string, regardless  
> > of the page displayed. That is  
> > “script/…/config/…/app/views/layouts/application.rhtml”
> > 
> > Have tried $0 which displays a consistent string, “script/server”.
> > 
> > Is there another variable, or another technique, to display the file  
> > names I desire? e.g. /app/views//
> > 
> > I’m new to ROR. Thank go to the Rails Space book!
> > 
> > Many thanks!
> 
> I am not sure if this will do it, but off the top of my head I would say  
> have a look in the params hash. Everytime an action is called, I think  
> the controller and action are pushed into the params hash.
> 
> This only works assuming that you are rendering a template for each  
> action and the template has the same name as the action (you would have  
> had to have overridden that behaviour).
> 
> Try accessing params[:controller] and params[:action]. If that works,  
> then the file will be found at  
> /app/views/params[:controller]/params[:action]
> 
> (Extensions will not be included)

---

<div class="post-metadata">

**Author:** ![drub](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e56c9b/32.png) [@drub](https://www.ruby-forum.com/u/drub)\
**Post date:** [November 21, 2007, 11:06pm UTC](https://www.ruby-forum.com/t/howto-display-file-being-executed/120839/4 "2007-11-21T23:06:52Z")

</div>

The other thing to check out, if you’re just looking to debug, is the  
log ( log/.log ). I tail it as I am developing and  
debugging my site. It will print the params hash for every request, as  
well as the SQL that is executed, benchmarks and what exactly is being  
rendered. If you would like to log your own info to that log, call

logger.info

from within a controller, model or view and have a look in the log.  
Very useful for debugging.

Good luck with the firehose.

Drub Drub wrote:

> Many thanks, ce bi. Ya got me thinking in the right direction. Bravo.
> 
> I found that
> 
> \<%= debug(params) %\>
> 
> works quite nicely. You’re right, params contains both the the action  
> and the controller. This line displays both.
> 
> Just what was needed.  
> Now, on to the next stumbling stone. 😉  
> Feel like I’m trying to drink from a fire hose!
> 
> Drub
> 
> ce bi wrote:
> 
> > Drub Drub wrote:
> > 
> > > Would like to display some debug code, the file being executed.
> > > 
> > > I want to see something like “File: app/views/site/file.rhtml”
> > > 
> > > Have tried displaying **FILE** and get a consistent string, regardless  
> > > of the page displayed. That is  
> > > “script/…/config/…/app/views/layouts/application.rhtml”
> > > 
> > > Have tried $0 which displays a consistent string, “script/server”.
> > > 
> > > Is there another variable, or another technique, to display the file  
> > > names I desire? e.g. /app/views//
> > > 
> > > I’m new to ROR. Thank go to the Rails Space book!
> > > 
> > > Many thanks!
> > 
> > I am not sure if this will do it, but off the top of my head I would say  
> > have a look in the params hash. Everytime an action is called, I think  
> > the controller and action are pushed into the params hash.
> > 
> > This only works assuming that you are rendering a template for each  
> > action and the template has the same name as the action (you would have  
> > had to have overridden that behaviour).
> > 
> > Try accessing params[:controller] and params[:action]. If that works,  
> > then the file will be found at  
> > /app/views/params[:controller]/params[:action]
> > 
> > (Extensions will not be included)
