Pagination on the same partial with different variables passed (will_paginate)
<p><strong>How do I use pagination on the same partial with different variables passed?</strong></p>

<p>I have a library show page in my Rails app that has a list of books:</p>

<p>libraries_controller.rb:</p>

<pre><code>def show 
  @books = @library.books.paginate(page: params[:books_page], per_page: 10)
end
</code></pre>

<p>libraries/show.haml:</p>

<pre><code>#books_table
  = render "books_list", books: @books
</code></pre>

<p>libraries/show.js.erb:</p>

<pre><code>$('#books_table').replaceWith('&lt;%= j render "books_list", books: @books %&gt;');
</code></pre>

<p>A 'books_list' partial has a pagination link which works fine:</p>

<p>books/_books_list.haml:</p>

<pre><code>...
= paginate books, param_name: 'books_page'
</code></pre>

<p>When I add a new book to the list, <code>#books_table</code> is automatically replaced with <code>_books</code> partial like so (books/create.js.erb):</p>

<pre><code>$('#books_table').replaceWith('&lt;%= j render "libraries/books_list", books: @library_books%&gt;')
</code></pre>

<p>books_controller.rb:</p>

<pre><code>def create
  @library_book = @library.books.create(book_params)
  @library_books = @library.books.paginate(page: params[:books_page], per_page: 10)
end
</code></pre>

<p>But at this point pagination doesn't work. Any ideas how should I proceed?</p>