Skip to content

Instantly share code, notes, and snippets.

@kivanio
Forked from adamrobbie/Gemfile
Created February 14, 2014 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kivanio/9001289 to your computer and use it in GitHub Desktop.
Save kivanio/9001289 to your computer and use it in GitHub Desktop.
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 examples...")
$.getScript(url)
$(window).scroll()
def index
@exampless = Examples.order("our_column").page(params[:page]).per_page(10)
end
gem 'will_paginate'
<div id="examples">
<%= render @examples %>
</div>
<%= will_paginate @examples %>
// Our ajax triggered code that corresponds with the rails controller action method.
$('#example').append('<%= j render(@exampless) %>');
<% if @exampless.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@examples) %>');
<% else %>
$('.pagination').remove();
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment