# Meta helper help

**URL:** <https://www.ruby-forum.com/t/meta-helper-help/105673>\
**Category:** Rails\
**Created:** [June 1, 2007, 8:18am UTC](https://www.ruby-forum.com/t/meta-helper-help/105673 "2007-06-01T08:18:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![johanatan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johanatan](https://www.ruby-forum.com/u/johanatan)\
**Post date:** [June 1, 2007, 8:18am UTC](https://www.ruby-forum.com/t/meta-helper-help/105673/1 "2007-06-01T08:18:58Z")

</div>

I’d like to write a helper thats used like this:

\<%= template\_info %\>

which replaces code like this:

\<% if RAILS\_ENV == “development” %\>

 Template: \<%= \_\_FILE\_\_ %\>
\<% end %\>

but when i write my helper it outputs the name of the helper file,  
not the template! Or just a string when I try to enclose it in \<% %\>  
How do i write a helper to output erb code thats then rendered as  
part of the calling template? is that possible?

def template\_info  
if RAILS\_ENV == “development”  
# **FILE**  
#"\<%= **FILE** %\>"  
#content\_tag(“div”, “\<%= **FILE** %\>”, :class =\>  
“template\_info” )  
end  
end

---

<div class="post-metadata">

**Author:** ![johanatan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johanatan](https://www.ruby-forum.com/u/johanatan)\
**Post date:** [June 2, 2007, 3:40am UTC](https://www.ruby-forum.com/t/meta-helper-help/105673/2 "2007-06-02T03:40:40Z")

</div>

hi, i found the answer – method “caller”

so here’s a neat little helper you also might like  
[http://pastie.caboo.se/67118](http://pastie.caboo.se/67118)

Now the question is, could i get render to insert this automatically  
at the end of each template (perhaps embeded in ) and toggle  
it with an environment config variable???

## helper

def template\_info( update = nil, \*info )  
if RAILS\_ENV == “development”  
info.insert(0, “Last update: " + update.to\_s(:short)) if update  
f = caller[0]  
f = f[0,f.index(‘:’)]  
f = f.split(”/“).last(2).join(”/“)  
info.insert(0, “Template: #{f}”)  
content\_tag(“div”, info.join(”  
"), :class =\>  
“template\_info” )  
end  
end

## template examples

\<%= template\_info %\>  
\<%= template\_info @page.updated\_at %\>  
\<%= template\_info @page.updated\_at, “by #{@page.author.name}” %\>

## example html result

Template: pages/show.html.erb  
Last update: 31 May 16:31
