Question

I made endless page scroll from tutorial http://railscasts.com/episodes/114-endless-page-revised?view=asciicast and it works.

But problem is that this javascript run endless page for every will paginate - even on other pages - for example, it try to endless paginate my messages box.

Script for this is very simple i think, but im nobie in javascript and just dont know how to tell script to endless scroll on only selected page and not for every will_paginate on project. I see that in JS file $('.paginate) - tell script to run for every paginate class.

I will be very grateful for tip.

JS in ERB:

$('.profile_list').append('<%= j render(@users) %>');

<% if @users.next_page %>

  $('.pagination').replaceWith('<%= j will_paginate(@users) %>');
<% else %>
  $('.pagination').remove();
<% end %>

And JS i JS file:

if ($('.pagination').length) {
$(window).scroll(function() {
  var url;
  url = $('.pagination .next_page').attr('href');

  if (url && $(window).scrollTop() > $(document).height() - $(window).height() - 50) {
    //$('.pagination').text('Fetching more products...')
    $.getScript(url)
Was it helpful?

Solution

well try including that js only in the pages you want, remove it from the application.js file and add it manualy on your page like this:

javascript_include_tag "yourjs.js"

here is a good example in this question: Rails 3.1 Pipeline - Exclude Javascript File

read the checked answer

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top