Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I found this question searching for paginating multiple models on the same page. It's not clear to me how the pagination for the @notes collection is intended to work, but as presented, the solutions will only paginate the @bookmarks collection via AJAX.</p> <p>There will be issues if you want to maintain pagination for both collections via html OR if you change the js file to render both collections. </p> <p>I implemented a solution to my similar problem like this:</p> <ol> <li>An html view that renders a template with two partials: one for <code>@notes</code> (including its pagination helper) and another that renders <code>@bookmarks</code> with its pagination helper</li> <li>Pagination links marked with <code>remote: true</code> </li> <li><p>One js view that re-renders the two partials, something like</p> <pre><code>$('#notes_container').html('&lt;%= j(render partial: 'paginated_notes_list') %&gt;'); $('#bookmarks_container').html('&lt;%= j(render partial: 'paginated_bookmarks_list'); %&gt;'); </code></pre></li> <li><p>This is the key: Pagination links that take the current page of the other model as a parameter. This way you do not "lose" which page you are on in the other model.</p> <pre><code>&lt;%= paginate @notes, param_name: 'page_1', params: {page_2: params[:page_2]} %&gt; &lt;%= paginate @bookmarks, param_name: 'page_2', params: {page_1: params[:page_1]} %&gt; </code></pre></li> </ol> <p>Again, I'm not really clear on how the asker's system is supposed to function, but this solution will allow user to page through both models without losing their "place" in the other model via AJAX or html.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload