From b88a6dbc39fcaa12dc58d06d4222f2443f02a32a Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Thu, 1 May 2008 13:27:21 -0700 Subject: Capture view errors in ActionView::Template. This means that errors raised by partials are caught by ActionView::PartialTemplate, which in turn means they have the proper filename and line number information. Signed-off-by: Pratik Naik --- actionpack/lib/action_view/base.rb | 13 ++----------- actionpack/lib/action_view/partial_template.rb | 2 +- actionpack/lib/action_view/partials.rb | 2 +- actionpack/lib/action_view/template.rb | 12 ++++++++++++ 4 files changed, 16 insertions(+), 13 deletions(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 4ed20fec89..bfd1a0ee0d 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -244,16 +244,7 @@ If you are rendering a subtemplate, you must now use controller-like partial syn template = Template.new(self, template_path, use_full_path, local_assigns) - begin - render_template(template) - rescue Exception => e - if TemplateError === e - e.sub_template_of(template.filename) - raise e - else - raise TemplateError.new(template, @assigns, e) - end - end + render_template(template) end # Renders the template present at template_path (relative to the view_paths array). @@ -290,7 +281,7 @@ If you are rendering a subtemplate, you must now use controller-like partial syn end def render_template(template) #:nodoc: - template.render + template.render_template end # Returns true is the file may be rendered implicitly. diff --git a/actionpack/lib/action_view/partial_template.rb b/actionpack/lib/action_view/partial_template.rb index 7d9c59a41c..ffcf258afe 100644 --- a/actionpack/lib/action_view/partial_template.rb +++ b/actionpack/lib/action_view/partial_template.rb @@ -24,7 +24,7 @@ module ActionView #:nodoc: def render_member(object) @locals[@counter_name] += 1 @locals[:object] = @locals[@variable_name] = object - returning render do + returning render_template do @locals.delete(@variable_name) @locals.delete(:object) end diff --git a/actionpack/lib/action_view/partials.rb b/actionpack/lib/action_view/partials.rb index 9afaa16918..b537eb8bf8 100644 --- a/actionpack/lib/action_view/partials.rb +++ b/actionpack/lib/action_view/partials.rb @@ -107,7 +107,7 @@ module ActionView case partial_path when String, Symbol, NilClass # Render the template - ActionView::PartialTemplate.new(self, partial_path, object_assigns, local_assigns).render + ActionView::PartialTemplate.new(self, partial_path, object_assigns, local_assigns).render_template when ActionView::Helpers::FormBuilder builder_partial_path = partial_path.class.to_s.demodulize.underscore.sub(/_builder$/, '') render_partial(builder_partial_path, object_assigns, (local_assigns || {}).merge(builder_partial_path.to_sym => partial_path)) diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index bc3d8d5e52..2cda3d94b5 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -17,6 +17,18 @@ module ActionView #:nodoc: @locals = locals || {} @handler = self.class.handler_class_for_extension(@extension).new(@view) end + + def render_template + render + rescue Exception => e + raise e unless filename + if TemplateError === e + e.sub_template_of(filename) + raise e + else + raise TemplateError.new(self, @view.assigns, e) + end + end def render prepare! -- cgit v1.2.3