We have to hook all 3 types.
The template is stored in @last_template.
module ActionView::Rendering
alias_method :_render_template_original, :_render_template
def _render_template(template, layout = nil, options = {})
@last_template = template
_render_template_original(template, layout, options)
end
end
module ActionView::Layouts
alias_method :_render_layout_original, :_render_layout
# Contains the logic that actually renders the layout.
def _render_layout(layout, locals, &block) #:nodoc:
@last_template = layout
_render_layout_original(layout, locals, &block)
end
end
module ActionView::Partials
alias_method :_render_partial_original, :_render_partial
def _render_partial(options, &block) #:nodoc:
prefix = self.controller_path unless options[:partial].include?(?/)
@last_template = self.find_template(options[:partial], prefix, true)
_render_partial_original(options, &block)
end
end