Skip to content

Instantly share code, notes, and snippets.

@bmaddy
Created May 9, 2014 20:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bmaddy/4567fad5aa55e5a600e1 to your computer and use it in GitHub Desktop.
Save bmaddy/4567fad5aa55e5a600e1 to your computer and use it in GitHub Desktop.
An initializer to show what parts of your page come from what rails partials
# Start the app with EXPLAIN_PARTIALS=true to show locations of view partials
if Rails.env.development? and ENV['EXPLAIN_PARTIALS']
module ActionView
class PartialRenderer
def render_with_explanation(*args)
rendered = render_without_explanation(*args).to_s
# Note: We haven't figured out how to get a path when @template is nil.
start_explanation = "\n<!-- START PARTIAL #{@template.inspect} -->\n"
end_explanation = "\n<!-- END PARTIAL #{@template.inspect} -->\n"
start_explanation.html_safe + rendered + end_explanation.html_safe
end
alias_method_chain :render, :explanation
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment