title: Mix HTML and non-HTML strings in Rails ERB
body: <p>I have a text-area where some users can input HTML (please, no comment about this being unsafe, I already have sanitized countermeasures).</p>
  
  <p>Now, I want to show an example of html code my user can write. How do I do that in my .erb template file with ruby?</p>
  
  <p>The visual output for the end user should look like this (Without syntax highlighting, respect line breaks !)</p>
  
  <p><code>my_example_string</code> :</p>
  
  <pre><code>Here is an example of sample code you can write in the text-area:
  &lt;p&gt;Hello, dear Mr. X, new announcement&lt;/p&gt;
  &lt;br&gt;
  &lt;h2&gt;The project&lt;/h2&gt;
  &lt;p&gt;blablabla&lt;/p&gt;
  &lt;h2&gt;Your role&lt;/h2&gt;
  &lt;p&gt;...&lt;/p&gt;
  </code></pre>
  
  <p><strong>EDIT</strong> : the actual HTML output looks like</p>
  
  <pre><code>&lt;p&gt;
          Here is an example of sample code you can write in the text-area: !&amp;lt;/p&amp;gt;
  &amp;lt;p&amp;gt;Hello, dear Mr. X, new announcement;/p&amp;gt;
  &amp;lt;h2&amp;gt;The project&amp;lt;/h2&amp;gt;
  &amp;lt;p&amp;gt;Blablabla&amp;lt;/p&amp;gt;
  ...
  &lt;/p&gt;
  </code></pre>
  
  <p>I have tried something like  </p>
  
  <pre><code>&lt;%= 'Here is an example of sample code you can write in the text-area:' +'&lt;br&gt;'.html_safe + 
      '&lt;br&gt;' + '&lt;br&gt;'.html_safe + 
      '&lt;p&gt;Hello, dear Mr. X, new announcement&lt;/p&gt;'+'&lt;br&gt;'.html_safe + 
      '&lt;h2&gt;The project'&lt;/h2&gt;' + ... %&gt;
  </code></pre>
  
  <p>But the output looks like (one single line)</p>
  
  <pre><code>Here is an example of sample code you can write in the text-area:&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;p&gt;Hello, dear Mr. X, new announcement&lt;/p&gt;&lt;br&gt;&lt;h2&gt;The project&lt;/h2&gt; 
  </code></pre>
  
  <p>Apparently I can't mix <code>.html_safe</code> and non <code>.html_safe</code> string</p>
  
  <p>Any idea ?</p>
  
  <p><strong>EDIT 2</strong> : </p>
  
  <p>I am actually using a custom helper/renderer which takes this pseudo-tooltip <code>my_example_string</code> as an argument</p>
  
  <p><em>my_view.html.erb</em></p>
  
  <pre><code>...
  &lt;%= render 'shared/field_with_tooltip',
          field: f.text_area(:body, placeholder: '', class: 'form-control', value: (@body if @body)),
          label: 'Body of the message',
          info: my_example_string %&gt;
  </code></pre>
  
  <p>My <code>field_with_tooltip</code> uses the info variable like this</p>
  
  <p><em>shared/field_with_tooltip.html.erb</em></p>
  
  <pre><code>...
  &lt;% if info %&gt;
      &lt;p class="text-info field-info"&gt;&lt;%= info %&gt;&lt;/p&gt;&lt;br&gt;
  &lt;% end %&gt;
  ...
  </code></pre>