Skip to content

Instantly share code, notes, and snippets.

@reiro
Created May 13, 2015 10:22
Show Gist options
  • Save reiro/f362819ce370fe3e83aa to your computer and use it in GitHub Desktop.
Save reiro/f362819ce370fe3e83aa to your computer and use it in GitHub Desktop.
Бесконечная пагинация
gem 'will_paginate'
gem 'bootstrap-sass'
gem 'bootstrap-will_paginate'
.paginate(page: params[:page], per_page: 15).order('created_at ASC')
<div id="my-autoservices">
<%= render @autoservices %>
</div>
<div id="infinite-scrolling">
<%= will_paginate %>
</div>
# pagination.js.coffee
jQuery ->
if $('#infinite-scrolling').size() > 0
$(window).on 'scroll', ->
more_autoservices_url = $('.pagination .next_page a').attr('href')
if more_posts_url && $(window).scrollTop() > $(document).height() - $(window).height() - 60
$('.pagination').html('<img src="/assets/ajax-loader.gif" alt="Loading..." title="Loading..." />')
$.getScript more_autoservices_url
return
return
respond_to do |format|
format.html
format.js
end
# index.js.erb
$('#my-autoservices').append('<%= j render @autoservices %>');
<% if @autoservices.next_page %>
$('.pagination').replaceWith('<%= j will_paginate @autoservices %>');
<% else %>
$(window).off('scroll');
$('.pagination').remove();
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment