will_paginate mit endlosem scrollen | Rails4
DAS IST DIE LÖSUNG
Also benutze ichwill_paginate / Bootstrap wird paginieren mit endlosem Scrollen.
So bringen Sie die Paginierung zum Laufen:
1.) In meinem Controller habe ich meine Indexaktion mit aktualisiert
@clips = Clip.order("created_at desc").page(params[:page]).per_page(20)
2.) Meine Indexansicht bearbeiten:
<%= will_paginate @clips%>
ERLEDIGT
Die Paginierung funktioniert einwandfrei.
To Add Endless scrolling
Ich habe die gleichen Schritte wie in meiner vorherigen Rails 3-App ausgeführt.
1.) Bearbeite meine 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.) Erstellen Sie eine index.js.erb mit:
$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 zu meiner Controller-Indexaktion hinzugefügt
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.) Mein _clip.html.erb ist mit dem div umwickelt
<div class="clip-box clips-masonry" data-no-turbolink>