public
Created — forked from ryanb/index.js.erb

Infinite scrolling solution covered in revised episode #114: http://railscasts.com/episodes/114-endless-page-revised

  • Download Gist
index.js.erb
HTML+ERB
1 2 3 4 5 6
$('#products').append('<%= j render(@products) %>');
<% if @products.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@products) %>');
<% else %>
$('.pagination').remove();
<% end %>
products.js.coffee
CoffeeScript
1 2 3 4 5 6 7 8
jQuery ->
if $('.pagination').length
$(window).scroll ->
url = $('.pagination .next_page').attr('href')
if url && $(window).scrollTop() > $(document).height() - $(window).height() - 50
$('.pagination').text("Fetching more products...")
$.getScript(url)
$(window).scroll()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.