title: How do I render a partial to a string?
body: <p>How do I render a partial to a string, so I can include it as part of a JSON response? I have to put it into a JSON response to allow room for a possible error message. The following code gives a 500 server error. If I use just a plain <code>render</code>, then surprisingly it works. Well, it send back just plain HTML which cannot be parsed as Javascript. </p>
  
  <h3>Code</h3>
  
  <pre><code>respond_to do |format|
     format.html { redirect_to post_path(post) }
     format.js { 
       { 
         error: "",
         content: (render_to_string partial: '/comments/comment', locals: {comment: comment}, layout: false )  
       } 
     }
  end
  </code></pre>
  
  <h3>Error</h3>
  
  <blockquote>
    <p>Template is missing
        Missing template comments/create, application/create with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :haml]}. Searched in: * "C:/Users/Chloe/workspace/project/app/views"</p>
  </blockquote>
  
  <h3>Works, but send back plain HTML</h3>
  
  <pre><code>render partial: '/comments/comment', locals: {comment: comment}, layout: false
  </code></pre>