title: will_paginate with endless Scrolling | Rails4
body: <p><strong>THIS IS THE SOLUTION</strong></p>
  
  <p>So i'm using <a href="https://github.com/mislav/will_paginate" rel="noreferrer">will_paginate</a> / <a href="https://github.com/yrgoldteeth/bootstrap-will_paginate" rel="noreferrer">Bootstrap Will Paginate</a> with Endless Scrolling.</p>
  
  <p>To get the Pagination working:</p>
  
  <p><strong>1.)</strong> In my Controller i updated my index action with</p>
  
  <pre><code>@clips = Clip.order("created_at desc").page(params[:page]).per_page(20)
  </code></pre>
  
  <p><strong>2.)</strong> Edit my index view:</p>
  
  <pre><code>&lt;%= will_paginate @clips%&gt;
  </code></pre>
  
  <p><strong>DONE</strong></p>
  
  <p>Pagination works just fine.</p>
  
  <p><code>To Add Endless scrolling</code> i did the same steps as in my previous Rails 3 App.</p>
  
  <p><strong>1.)</strong> Edit my clips.js.coffee
  </p>
  
  <pre><code>jQuery -&gt;
  $('#clips-masonry').imagesLoaded -&gt;
      $('#clips-masonry').masonry itemSelector: ".clips-masonry" # Thats my Masonry
  
  if $('.pagination').length # Thats for the Endless Scrolling
      $(window).scroll -&gt;
          url = $('.pagination .next_page a').attr('href')
          if url &amp;&amp; $(window).scrollTop() &gt; $(document).height() - $(window).height() - 50
              # What to do at the bottom of the page
              $('.pagination').text("Fetching more Clips...")
              $.getScript(url)
          $(window).scroll()
  </code></pre>
  
  <p><strong>2.)</strong> Create an index.js.erb with:</p>
  
  <pre><code>$boxes = $('&lt;%= j render(@clips) %&gt;')
  
  $('#clips-masonry').append( $boxes ).imagesLoaded( function(){
    $('#clips-masonry').masonry( 'reload');
  });
  &lt;% if @clips.next_page %&gt;
    $('.pagination').replaceWith('&lt;%= j will_paginate(@clips) %&gt;');
  &lt;% else %&gt;
    $('.pagination').remove();
  &lt;% end %&gt;
  </code></pre>
  
  <p><strong>3.)</strong> Added format.js to my Controller index action</p>
  
  <pre><code>def index
      @clips = Clip.order("created_at desc").page(params[:page]).per_page(12)
      respond_to do |format|
          format.html
          format.js
      end
  end
  </code></pre>
  
  <p><strong>4.)</strong> My _clip.html.erb is wrapped with the div</p>
  
  <pre><code> &lt;div class="clip-box clips-masonry" data-no-turbolink&gt;
  </code></pre>