Skip to content

Commit

Permalink
Capture view errors in ActionView::Template.
Browse files Browse the repository at this point in the history
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 <pratiknaik@gmail.com>
  • Loading branch information
nex3 authored and lifo committed May 2, 2008
1 parent f6ec296 commit b88a6db
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
13 changes: 2 additions & 11 deletions actionpack/lib/action_view/base.rb
Expand Up @@ -244,16 +244,7 @@ def render_file(template_path, use_full_path = true, local_assigns = {}) #:nodoc

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 <tt>template_path</tt> (relative to the view_paths array).
Expand Down Expand Up @@ -290,7 +281,7 @@ def render(options = {}, local_assigns = {}, &block) #:nodoc:
end

def render_template(template) #:nodoc:
template.render
template.render_template
end

# Returns true is the file may be rendered implicitly.
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/partial_template.rb
Expand Up @@ -24,7 +24,7 @@ def render
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
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/partials.rb
Expand Up @@ -107,7 +107,7 @@ def render_partial(partial_path, object_assigns = nil, local_assigns = {}) #:nod
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))
Expand Down
12 changes: 12 additions & 0 deletions actionpack/lib/action_view/template.rb
Expand Up @@ -17,6 +17,18 @@ def initialize(view, path, use_full_path, locals = {})
@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!
Expand Down

0 comments on commit b88a6db

Please sign in to comment.