title: Rendering partial inside js.erb. Is it possible to get raw string so I can strip whitespace?
body: <p>I want to render a partial in my js.erb file so I can use the generated HTML in my Javascript. Here's some code to serve as an example.</p>
  
  <p><strong>create.js.erb</strong></p>
  
  <pre><code>$(function(){
    var html = "&lt;%= render(:partial =&gt; `pretty_box`) %&gt;";
    $("#container").prepend(html);
  });
  </code></pre>
  
  <p><strong>_pretty_box.html.haml</strong></p>
  
  <pre><code>.pretty_box_container
    .title
      Something Pretty
  </code></pre>
  
  <p>When create.js.erb is rendered, I get the following:</p>
  
  <pre><code>$(function(){
    var html = "&lt;div class="pretty_box_container&gt;
      &lt;div class="title"&gt;
        Something Pretty
      &lt;/div&gt;
  &lt;/div&gt;";
    $("#container").prepend(html);
  });
  </code></pre>
  
  <p>As you would expect, this breaks my javascript. I need to strip the whitespace from the result of rendering the partial. The problem is the return value of <code>render</code> is an <a href="http://api.rubyonrails.org/classes/ActiveSupport/SafeBuffer.html" rel="noreferrer"><code>ActiveSupport::SafeBuffer</code></a> object, which overrides all "unsafe" methods (see <a href="http://api.rubyonrails.org/classes/ActiveSupport/SafeBuffer.html" rel="noreferrer"><strong>UNSAFE_STRING_METHODS</strong></a>), including <code>strip</code>. So calling <code>render(:partial =&gt;</code>pretty_box<code>).strip</code> HTML-encodes the entire string.</p>
  
  <p>I've tried all sorts of combinations using the methods <code>html_safe</code> or <code>to_s</code>. They don't work because they return <code>self</code>, and using <code>raw</code> doesn't work either because it calls <code>to_s.html.safe</code>.</p>
  
  <p>I know I can append <code>&gt;</code> and <code>&lt;</code> characters to my HAML, but I don't want to do that for every line of every partial.</p>