RailsとKaminariを使用しており、LocationsandPostsの下のコメントに無限のスクロールを実装しようとしています。始めは正しかったのですが、下にスクロールすると、同じコメントが何度も読み込まれます。コメントが正しく読み込まれるようにするにはどうすればよいですか?
これが私のlocations/show.js.erbです
1 $('#comments').append('<%= j render(@comments) %>');
これが私のcomments.jsです
5 jQuery ->
6 $(window).scroll ->
7 if $(window).scrollTop() > $(document).height() - $(window).height() - 200
8 $.getScript($('.pagination .next_page a').attr('href'))
私のコメントコントローラーはアクションを表示します
18 def show
19 @title = @location.name
20 @comments = @location.comments.order("created_at desc").page(params[:page]).per(35)
21 @commentable = @location
22 @comment = @location.comments.build
23 respond_to do |format|
24 format.html
25 format.js
26 end
27 end
編集:これはページネーションのhtmlソースです
<div class="pagination">
<ul>
<li class="active">
<a href="#">1</a>
</li>
<li class="">
<a href="/locations/1?page=2" rel="next">2</a>
</li>
<li class="">
<a href="/locations/1?page=3">3</a>
</li>
<li class="">
<a href="/locations/1?page=4">4</a>
</li>
<li class="">
<a href="/locations/1?page=5">5</a>
</li>
<li>
<a href="/locations/1?page=5">Last »</a>
</li>
</ul>
</div>