我正在尝试实现 Railscasts 第 114 集中显示的无限页面功能。分页效果很好,但根本没有触发无限页面功能。我没有看到任何错误;只是分页,好像我没有添加无尽的页面 javascript。我的代码:
活动控制器
class ActivitiesController < ApplicationController
before_filter :authenticate_user!
def index
@activities = PublicActivity::Activity.order("created_at DESC").where(owner_type: "User", owner_id: current_user.followed_users.map {|u| u.id}).page(params[:page]).per_page(15)
@post = current_user.posts.build
respond_to do |format|
format.html
format.json
format.js
end
end
end
活动.js.coffee
jQuery ->
if $('.pagination').length
$(window).scroll ->
url = $('.pagination .next_page').attr('href')
if url && $(window).scrollTop() > $(document).height() - $(window).height() - 50
$('.pagination').text("Loading more activities...")
$.getScript(url)
$(window).scroll()
index.js.erb
$('#activities').append('<%= j render ('shared/activities') %>');
<% if @activities.next_page %>
$('.pagination').replaceWith('<%= j will_paginate('shared/activities') %>');
<% else %>
$('.pagination').remove();
<% end %>
<% sleep 1 %>
共享/_activities.html.erb
<div class="activities">
<% @activities.each do |activity| %>
<code>
<% end %>
<%= will_paginate @activities %>
</div>
问题必须与javascript有关,但我无法弄清楚。关于可能导致问题的任何想法?
谢谢!-b