-
-
Save luciuschoi/da7da0b28610628ce894576385277088 to your computer and use it in GitHub Desktop.
Rails Endless pagination
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def index | |
@exampless = Examples.order("our_column").page(params[:page]).per_page(10) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'will_paginate' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="examples"> | |
<%= render @examples %> | |
</div> | |
<%= will_paginate @examples %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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