14
这让我使用will_paginate/Bootstrap Will Paginate无休止的滚动SOLUTIONwill_paginate无限滚动| Rails4
。
要获得分页工作:
1)在我的控制器我更新我的索引行动
@clips = Clip.order("created_at desc").page(params[:page]).per_page(20)
2)编辑我的索引视图:
<%= will_paginate @clips%>
DONE
分页工作得很好。
To Add Endless scrolling
我做相同的步骤,在我以前的Rails 3应用程序。
1)编辑我clips.js.coffee
jQuery ->
$('#clips-masonry').imagesLoaded ->
$('#clips-masonry').masonry itemSelector: ".clips-masonry" # Thats my Masonry
if $('.pagination').length # Thats for the Endless Scrolling
$(window).scroll ->
url = $('.pagination .next_page a').attr('href')
if url && $(window).scrollTop() > $(document).height() - $(window).height() - 50
# What to do at the bottom of the page
$('.pagination').text("Fetching more Clips...")
$.getScript(url)
$(window).scroll()
2)创建一个带有index.js.erb的:
$boxes = $('<%= j render(@clips) %>')
$('#clips-masonry').append($boxes).imagesLoaded(function(){
$('#clips-masonry').masonry('reload');
});
<% if @clips.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@clips) %>');
<% else %>
$('.pagination').remove();
<% end %>
3)新增format.js到我的控制器的索引动作
def index
@clips = Clip.order("created_at desc").page(params[:page]).per_page(12)
respond_to do |format|
format.html
format.js
end
end
4)我_clip.html.erb被包裹在div
<div class="clip-box clips-masonry" data-no-turbolink>
什么问题?无尽的滚动分页代码将起作用(尽管它不是turbolinks友好的) - 如果列出错误,您可能会得到一些见解。 – trh
问题是,它不工作:),没有错误,无尽的只是不工作:(我认为它必须与format.js,我必须包括在我的控制器。但在Rails 4控制器改变了,我不能得到它的工作 –
它对我来说工作正常,我仍然使用与format.js respond_to块。什么是事件调用你的日志,HTML?像'剪辑?page = 2 ''ClipsController#index as HTML'? – trh