title: Render output of HTML stored in database in Rails
body: <p>I have some html content stored in a database field. I would like trusted admins in our system to be able to edit the HTML when needed.  Eventually this html will be converted into an email message and sent to users.  In addition to the static html content, the email message has a first and last name that is stored in an active record model.</p>
  
  <p>I was hoping to leave the <code>&lt;%= user.firstname user.lastname %&gt;</code> inside the HTML text when the admins are editing the content and then eventally combine the content with embedded erb the email renderer. I have the part where the admins can save the HTML working fine.</p>
  
  <p>However, even ignoring the email and just trying to render to a normal web page, I am not able to get a view to correctly substitute the embedded <code>&lt;%= ... %&gt;</code> with the information from the database. I always see the <code>&lt;%= ... %&gt;</code> instead of the substituted text. I have tried render_to_string, render :inline, etc.</p>
  
  <p>In summary, I am trying to:</p>
  
  <ol>
  <li>Take some html text with embedded some erb from the database</li>
  <li>Run the text through a template where the embedded erb is replaced with the variables passed into locals</li>
  <li>Take the resulting text block and either email it to users or display on a web page depending on my needs</li>
  </ol>
  
  <p>The problem is that the results always have the <code>&lt;%= ... %&gt;</code> in it instead of the substitutions.</p>
  
  <p>In an example controller I have:</p>
  
  <pre><code> def showit
      @storedhtml = mymodel.savedhtml
      @emailtext = render_to_string( template: 'e.html.erb',
        layout: false, locals: { user:@user })
     end
  </code></pre>
  
  <p>The e.html.erb contains:</p>
  
  <pre><code>&lt;%= raw @storedhtml %&gt;
  </code></pre>
  
  <p>and the showit.html.erb has:</p>
  
  <pre><code>= raw @emailtext
  </code></pre>
  
  <p>I have also tried using inline like this:</p>
  
  <pre><code>def showit
       # the line below is substituted but the &lt;p&gt; tags are not converted
      @stuff = "&lt;%= '&lt;p&gt;testme&lt;/p&gt;' + user.firstname %&gt;"  
      @storedhtml = mymodel.the_html_content
      @output = render( inline: @storedhtml, locals: { user:@user }, layout: true )
  end
  </code></pre>