Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Infinite scrolling solution covered in revised episode #114: http://railscasts.com/episodes/114-endless-page-revised
$('#products').append('<%= j render(@products) %>');
<% if @products.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@products) %>');
<% else %>
$('.pagination').remove();
<% end %>
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()
@ryanb

This comment has been minimized.

Copy link
Owner Author

@ryanb ryanb commented Dec 16, 2011

This assumes you have existing pagination already in place. See Episode 114: Endless Page (revised) for a walkthrough on how this works.

@jnx

This comment has been minimized.

Copy link

@jnx jnx commented Dec 17, 2011

Nice :)

@toamitkumar

This comment has been minimized.

Copy link

@toamitkumar toamitkumar commented Dec 17, 2011

bingo !!!

@czj

This comment has been minimized.

Copy link

@czj czj commented Dec 18, 2011

Very compact, very nice !

@richardsondx

This comment has been minimized.

Copy link

@richardsondx richardsondx commented Apr 4, 2012

I've been having some issues with this as i am loosing all the style of my posts when I try to do endless pages. How would you do the same thing while using a partial and <%= render 'micro posts' %> instead of <%= render @microposts %> ??

Here is my code I haven't been able to fix this issue:

https://gist.github.com/2305229

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment