Rails: How To Modify Template Contents Before Rendering
Just a quick snippet to modify template contents before ActionView render them via ERB.
ActionView::Base.class_eval do
alias_method :action_view_render_template, :render_template
def render_template(template_extension, template, file_path = nil, local_assigns = {})
template ||= read_template_file(file_path, template_extension)
template = "#{template}" # add your contents here.
action_view_render_template(template_extension, template, file_path, local_assigns)
end
end
You can add this code to environment.rb, but is preferible a plugin.