Will_paginate With Endless Scrolling | Rails4
THIS IS THE SOLUTION So i'm using will_paginate / Bootstrap Will Paginate with Endless Scrolling. To get the Pagination working: 1.) In my Controller i updated my index action with
Solution 1:
Ok, i got it working with my Updated Question, everyone who stumbles upon this problem, This is the solution.
Solution 2:
Incase someone prefers to use JS/JQUERY:
$(window).scroll(function() {
var url;
// Checks if products are currently being loadedif (window.pagination_loading) {
return;
}
// Grabs the URL from the "next page" button
url = $('.pagination .next_page').attr('href')
// Chckes if you're n height from the bottomif (url && $(window).scrollTop() > $(document).height() - $(window).height() - 50) {
// Variable to know that you are currently loading productswindow.pagination_loading = true;
// Text while loading
$('.pagination').text('');
// Run the scriptreturn $.getScript(url).always(function() {
returnwindow.pagination_loading = false;
});
}
});
Index.js.erb:
$products = $('<%= j render(@products) %>')
$('#productsContainer').append( $products );
<% if@products.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@products) %>');
<% else %>
$('.pagination').remove();
<% end %>
index.html.erb
<divclass="container">
<%= will_paginate @products %>
</div>
Controller:
respond_to do |format|
format.html
format.js
end
Post a Comment for "Will_paginate With Endless Scrolling | Rails4"