Home > Software design >  How to show the name of a partial in the generated HTML itself
How to show the name of a partial in the generated HTML itself

Time:01-18

I searched but couldn't find a straightforward answer. I would like to be able to see which partial generated a certain piece of HTML. So when in a view I would say:

<%= render :partial => 'stackoverflow', locals: { answers: "johny be good" } %>

with e.g. app/views/_stackoverflow.html.erb containing

<p><%= answers %></p>
<hr>

that the resulting HTML would inject a html comment with the name of the rendered partial like:

<!-- partial: 'app/views/_stackoverflow.html.erb' -->
<p>johny be good</p>
<hr>

I assume there is a configuration option for this, but can't seem to find anything.

I know that the rendered partials are shown in the rails server log, but that is not what I am looking for.

Any help would be greatly appreciated.

CodePudding user response:

To be fair, I have to look it up every single time, because I can never remember the name for this config:
https://guides.rubyonrails.org/configuring.html#config-action-view-annotate-rendered-view-with-filenames

You should already have it in development.rb, just uncomment it:

# config/environments/development.rb

# Annotate rendered view with file names.
config.action_view.annotate_rendered_view_with_filenames = true
  • Related