will_paginate与无尽的滚动| Rails4 [英] will_paginate with endless Scrolling | Rails4
问题描述
这就是解决方案
所以我正在使用 will_paginate / Bootstrap Will Paginate with Endless Scrolling。
So i'm using will_paginate / Bootstrap Will Paginate with Endless Scrolling.
要让分页工作:
1。)在我的控制器中我更新了我的索引操作
1.) In my Controller i updated my index action with
@clips = Clip.order("created_at desc").page(params[:page]).per_page(20)
2。)编辑我的索引视图:
<%= will_paginate @clips%>
完成
分页工作正常。
添加无限滚动
我做了与之前的Rails 3相同的步骤App。
To Add Endless scrolling
i did the same steps as in my previous Rails 3 App.
1。)编辑我的clips.js.coffee
1.) Edit my 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:
2.) Create an index.js.erb with:
$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。)在我的Controller索引操作中添加了format.js
3.) Added format.js to my Controller index action
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
4.) My _clip.html.erb is wrapped with the div
<div class="clip-box clips-masonry" data-no-turbolink>
推荐答案
好的,我使用了我的更新问题,每个遇到这个问题的人,这都是解决方案。
Ok, i got it working with my Updated Question, everyone who stumbles upon this problem, This is the solution.
这篇关于will_paginate与无尽的滚动| Rails4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!