Skip to content

Instantly share code, notes, and snippets.

@bess
Forked from bmaddy/explain_partials.rb
Created May 30, 2017 17:37
Show Gist options
  • Save bess/85f6bdb48eea61d9a841dea72eead8b7 to your computer and use it in GitHub Desktop.
Save bess/85f6bdb48eea61d9a841dea72eead8b7 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
@bess
Copy link
Author

bess commented May 30, 2017

Save this file to config/initializers/explain_partials.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment