title: My posts page get doubled. Rails, ajax, jquery
body: <p>I added ajax to my rails blog. It worked with only one post, but something weird is going on after I added next. I get copies of my posts on this same page.</p>
  
  <p><strong>Comments_controller.rb</strong></p>
  
  <pre><code> class CommentsController &lt; ApplicationController
      def create
          @posts = Post.all
          @post = Post.find(params[:post_id])
          @comment = @post.comments.create!(params[:comment])
  
          respond_to do |format|
              format.html {redirect_to @post}
              format.js
          end
      end
  
  end
  </code></pre>
  
  <h1>index.html.erb</h1>
  
  <pre><code>&lt;%= render 'post' %&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>create.js.erb</strong></p>
  
  <pre><code>  $('.post').html("&lt;%= escape_javascript(render("posts/post")) %&gt;") });
  </code></pre>
  
  <p><strong>_post.html.erb</strong></p>
  
  <pre><code> &lt;% @posts.each do |post| %&gt;
          &lt;div class="post"&gt;
              &lt;p&gt;&lt;strong&gt; &lt;%= post.title %&gt; &lt;/strong&gt;, posted &lt;%= post.created_at.to_date %&gt; &lt;/p&gt; &lt;br /&gt;
              &lt;%= post.content %&gt; &lt;br /&gt;
  
              &lt;%= simple_form_for [post, post.comments.build], :remote =&gt; true do |f| %&gt;
                  &lt;%= f.input :content %&gt;
                  &lt;%= f.button :submit %&gt;
              &lt;% end %&gt;
  
              &lt;%= render :partial =&gt; 'comment', :locals =&gt; {:post =&gt; post} %&gt;
          &lt;/div&gt;
  
      &lt;% end %&gt;
  </code></pre>
  
  <p><strong>_comment.html.erb</strong></p>
  
  <pre><code>&lt;div class = "comment"&gt;
    &lt;ol&gt;
      &lt;% post.comments.each do |comment| %&gt;
        &lt;li&gt; &lt;%= comment.content %&gt;&lt;/li&gt;
      &lt;% end %&gt;
    &lt;/ol&gt;
  &lt;/div&gt;
  </code></pre>