I am currently using a modified version of Peter Ehrlich's solution. The resulting string has the form controller_name/view_name , for example. users/new , which means that it can be passed directly to render later or modified for other purposes. I only tried this with Rails 4.2, although as far as I know it should completely go back to 3.xes.
ActionView::Base.class_eval do attr_accessor :current_template end ActionView::TemplateRenderer.class_eval do def render_template_with_current_template_accessor(template, layout_name = nil, locals = {}) @view.current_template = template.try(:virtual_path) render_template_without_current_template_accessor(template, layout_name, locals) end alias_method_chain :render_template, :current_template_accessor end
Brent royal-gordon
source share