HowTo: Display file being executed?

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!

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)

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. :wink:
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)

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. :wink:
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)