Note that there are some explanatory texts on larger screens.

plurals
  1. POdouble pagination with will_paginate and ajax
    text
    copied!<p>I'm implementing a double pagination in a single page with ajax. One of this pagination is endless page, but I think it's doesn't matter.</p> <p>Well my code it's quite simple:</p> <p>Controller:</p> <pre><code>@products = @brand.products.search(params[:search]).paginate(:page =&gt; params[:product_page], :per_page =&gt; 3) @comments = @brand.comments.paginate(:page =&gt; params[:comment_page], :per_page =&gt; 5) </code></pre> <p>show.html.erb</p> <pre><code>&lt;%= will_paginate @comments, :param_name =&gt; 'comment_page' %&gt; &lt;%= will_paginate @products, :param_name =&gt; 'product_page' %&gt; </code></pre> <p>And show.js.erb (this is what is wrong)</p> <pre><code>//Endless comment pagination &lt;% if params[:paginate] == 'comment_page' %&gt; $("#comments").append("&lt;%= j ( render @comments) %&gt;"); &lt;% if @comments.next_page %&gt; $(".pagination").replaceWith("&lt;%= j will_paginate @comments %&gt;"); &lt;% else %&gt; $('.pagination').remove(); &lt;% end %&gt; &lt;% end %&gt; &lt;% if params[:paginate] == 'product_page'%&gt; //Product pagination $('#products').html('&lt;%= escape_javascript(render :partial =&gt; "products") %&gt;'); //I put this because if I didn't, ajax just works once. $('.pagination a').attr('data-remote', 'true'); &lt;% end %&gt; </code></pre> <p>but params[:paginate] == 'comment_page' and params[:paginate] == 'product_page' doesn't work.</p> <p>If I don't put that couple lines, it works, but when I paginate one of them, the other one paginates too.</p> <p>Thanks!</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