[英]Why is this infinite scroll using will_paginate not working?
I'm trying to get all posts from all users to be loaded via infinite scroll using will_paginate. 我正在尝试使用will_paginate通过无限滚动加载所有用户的所有帖子。 Right now it's showing only the normal pagination. 现在,它仅显示正常的分页。 I am very confused. 我很困扰。 But then again, I'm a newbie. 但是话又说回来,我是新手。 I'd appreciate any help. 我将不胜感激。
index.html.erb: index.html.erb:
<script>
$('#my-posts');
<% if @posts.next_page %>
$('.pagination').replaceWith('<%= j will_paginate @posts %>');
<% else %>
$(window).off('scroll');
$('.pagination').remove();
<% end %>
</script>
<div id="my-posts">
<% @posts.each do |post| %>
#...posts and and their comments
<% end %>
</div>
<div id="infinite-scrolling">
<%= will_paginate %>
</div>
pagination.js.coffee (also tried pagination.coffee): pagination.js.coffee(也尝试过pagination.coffee):
jQuery ->
if $('#infinite-scrolling').size() > 0
$(window).on 'scroll', ->
more_posts_url = $('.pagination .next_page a').attr('href')
if more_posts_url && $(window).scrollTop() > $(document).height() - $(window).height() - 60
$('.pagination').html('<p> loading <p>')
$.getScript more_posts_url
return
return
posts controller: 职位控制器:
respond_to do |format|
format.html
format.js
end
@posts = Post.paginate(page: params[:page], per_page: 15).order('created_at DESC')
need to change controller code to this 需要将控制器代码更改为此
@posts = Post.paginate(page: params[:page], per_page: 15).order('created_at DESC')
respond_to do |format|
format.html
format.js
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.