提交 b88a6dbc 编写于 作者: N Nathan Weizenbaum 提交者: Pratik Naik

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: NPratik Naik <pratiknaik@gmail.com>
上级 f6ec296a
......@@ -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).
......@@ -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.
......
......@@ -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
......
......@@ -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))
......
......@@ -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!
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册