Skip to content

option to enable partial rendering debugging comments #15035

@phoet

Description

@phoet

when looking at a rendered html page, it's often hard to tell where the code of a partial lives inside the views directory.

in order to simplify the process of finding the proper file, i find myself dropping this extension into my rails projects:

if Rails.env.development?
  module My
    module PartialRenderer
      def render(context, options, block)
        msg = "rendering '#{options[:partial]}' with locals '#{(options[:locals] || {}).keys}'"
        "<!-- start #{msg}-->\n#{super(context, options, block)}\n<!-- end #{msg}-->\n".html_safe
      end
    end
  end

  ActionView::PartialRenderer.prepend(My::PartialRenderer)
end

this will generate comments around the partial, so it's easy to spot the right files while looking at the html source:

<!-- start rendering 'some_partial' with locals '[:all, :assigned, :locals]'-->
<div class="hello">
    <div class="world">
      [...]
    </div>
</div>
<!-- end rendering 'some_partial' with locals '[:all, :assigned, :locals]'-->

i would like to propose a PR that adds this functionality to rails, but beforehand, i would like to discuss the best approach of integrating this and whether this has a chance of getting merged into master.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions