title: Rendering two partials with a form using ajax
body: <p>I'm rendering a partial that renders a form, using ajax (I can't just render the form directly). Posting a comment works fine when I'm rendering the form without ajax but with ajax it seems the partial can't access the @post variable.</p>
  
  <pre><code>&lt;%= link_to "Render form", submit_comment_path, :remote =&gt; true  %&gt;
  
  &lt;div id="form"&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I have a submit_comment.js file that looks like this:</p>
  
  <pre><code>$("#form").html("&lt;%= j render(partial: 'comment_partial', locals: {post: @post}) %&gt;");
  </code></pre>
  
  <p>The comment_partial view:</p>
  
  <pre><code>&lt;%= render 'comments/form' %&gt;
  </code></pre>
  
  <p>The form view:</p>
  
  <pre><code>&lt;%= simple_form_for [post, Comment.new] %&gt;
  
  ...
  </code></pre>
  
  <p>The submit_comment_path route: </p>
  
  <pre><code> get  '/submit_comment', to: 'posts#submit_comment', as: :submit_comment
  </code></pre>
  
  <p>The posts controller (it's being rendered on the show page):</p>
  
  <pre><code>def show
    @post = Post.find(params[:id])    
  end
  
  def submit_comment
   respond_to do |format|
    format.html
    format.js
   end
  end
  </code></pre>
  
  <p>and the comments controller:</p>
  
  <pre><code>def create
   @post = Post.find(params[:post_id])
  end
  </code></pre>
  
  <p>If I try to post a new comment it gives me a routing error and takes me to <code>/posts//comment</code>. Putting <code>post.id</code> in the comment_partial gives me an undefined error.</p>