I work with a lot of designers. The question I get all the time is:
Where is the template that displays xyz? I was thinking it would be
nice if rails would print the name of each template it loads as an
html comment like so:
Not having to answer these questions all day would really make my day.
I poked around the rails code for a couple hours and don't see an
obvious way. Does anyone have an idea on how to do this?
On Apr 3, 2:06 pm, mixtli <ronmcclai...@gmail.com> wrote:
> I work with a lot of designers. The question I get all the time is:
> Where is the template that displays xyz? I was thinking it would be
> nice if rails would print the name of each template it loads as an
> html comment like so:
Seems like you can do this by overriding render_template in
template.rb. Seems like a fairly handy idea actually, when I have
worked with designers that's definitely a question that has come up
often!
> Not having to answer these questions all day would really make my day.
> I poked around the rails code for a couple hours and don't see an
> obvious way. Does anyone have an idea on how to do this?
> I work with a lot of designers. The question I get all the time is:
> Where is the template that displays xyz? I was thinking it would be
> nice if rails would print the name of each template it loads as an
> html comment like so:
> Not having to answer these questions all day would really make my day.
> I poked around the rails code for a couple hours and don't see an
> obvious way. Does anyone have an idea on how to do this?
For now, I just slapped this in a file in lib and include it in
environment.rb:
module ActionView
class Template
def render_template(view, local_assigns = {})
"<!-- TEMPLATE: #{self.template_path} -->\n" + render(view,
local_assigns)
rescue Exception => e
raise e unless filename
if TemplateError === e
e.sub_template_of(self)
raise e
else
raise TemplateError.new(self, view.assigns, e)
end
end
end
end
Works in Rails 2.3 anyway. I'm sure there is a cleaner way, and it
should probably be made into an environment specific config option.
But I'm in a hurry right now.
Use "<!-- TEMPLATE: #{self.load_path}/#{self.template_path} -->\n"
instead to get the full path from RAILS_ROOT. Useful if you're
pulling in views from plugins/engines.
> module ActionView
> class Template
> def render_template(view, local_assigns = {})
> "<!-- TEMPLATE: #{self.template_path} -->\n" + render(view,
> local_assigns)
> rescue Exception => e
> raise e unless filename
> if TemplateError === e
> e.sub_template_of(self)
> raise e
> else
> raise TemplateError.new(self, view.assigns, e)
> end
> end
> end
> end
> Works in Rails 2.3 anyway. I'm sure there is a cleaner way, and it
> should probably be made into an environment specific config option.
> But I'm in a hurry right now.
> Fred
>> module ActionView
>> class Template
>> def render_template(view, local_assigns = {})
>> "<!-- TEMPLATE: #{self.template_path} -->\n" + render(view,
>> local_assigns)
>> rescue Exception => e
>> raise e unless filename
>> if TemplateError === e
>> e.sub_template_of(self)
>> raise e
>> else
>> raise TemplateError.new(self, view.assigns, e)
>> end
>> end
>> end
>> end
>> Works in Rails 2.3 anyway. I'm sure there is a cleaner way, and it
>> should probably be made into an environment specific config option.
>> But I'm in a hurry right now.
> I work with a lot of designers. The question I get all the time is:
> Where is the template that displays xyz? I was thinking it would be
> nice if rails would print the name of each template it loads as an
> html comment like so:
> Not having to answer these questions all day would really make my day.
> I poked around the rails code for a couple hours and don't see an
> obvious way. Does anyone have an idea on how to do this?
I'm using it and it's cool, but it should probably check if any layout statement is present on the controller: if layout is nil then I probably don't need/want any comment in the template :)
On Apr 8, 1:54 am, Emanuele Tozzato <etozz...@gmail.com> wrote:
> I'm using it and it's cool, but it should probably check if any layout
> statement is present on the controller: if layout is nil then I
> probably don't need/want any comment in the template :)
More precisely if what it's rendering isn't html it probably shouldn't
be putting html comments in!