简体   繁体   中英

double pagination with will_paginate and ajax

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.

Well my code it's quite simple:

Controller:

@products = @brand.products.search(params[:search]).paginate(:page => params[:product_page], :per_page => 3)

@comments = @brand.comments.paginate(:page => params[:comment_page], :per_page => 5) 

show.html.erb

<%= will_paginate @comments, :param_name => 'comment_page' %>
<%= will_paginate @products, :param_name => 'product_page' %>

And show.js.erb (this is what is wrong)

//Endless comment pagination
<% if params[:paginate] == 'comment_page' %>
  $("#comments").append("<%= j ( render @comments) %>");
  <% if @comments.next_page %>
    $(".pagination").replaceWith("<%= j will_paginate @comments %>");
  <% else %>
    $('.pagination').remove();
  <% end %>
<% end %>

<% if params[:paginate] == 'product_page'%>
  //Product pagination
  $('#products').html('<%= escape_javascript(render :partial => "products") %>');
  //I put this because if I didn't, ajax just works once.
  $('.pagination a').attr('data-remote', 'true');
<% end %>

but params[:paginate] == 'comment_page' and params[:paginate] == 'product_page' doesn't work.

If I don't put that couple lines, it works, but when I paginate one of them, the other one paginates too.

Thanks!

代替:param_name will_paginate helper上的:param_name键,尝试:params

  <%= will_paginate @comments, params: { paginate: "comment_page" } %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM