hi, i found the answer -- method "caller"
so here''s a neat little helper you also might like
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("<br />"), :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
<div class="template_info">Template: pages/show.html.erb<br
/>Last
update: 31 May 16:31</div>
On Jun 1, 2:18 am, Jonathan Linowes
<lino...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I''d like to write a helper thats used like this:
>
> <%= template_info %>
>
> which replaces code like this:
>
> <% if RAILS_ENV == "development" %>
> <div class="template_info">
> Template: <%= __FILE__ %>
> </div>
> <% 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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---