I have seen something similar asked before, but I can not understand it, and I can not ask for help there because of low reputation to comment.
So, I am asking a new question. I am using will_paginate plug in for two objects on the same page, and they are working but both move simultaneously. For example, if I click page 2 on the first, page 2 changes even in the second pagination.
This is my code in the controller:
@tasks = @student.tasks.paginate(page: params[:page], :per_page => 2)
@plans = @student.plans.paginate(page: params[:page], :per_page => 2)
And this is my code in the view:
<%= will_paginate @tasks %>
<%= will_paginate @plans %>
How can I make this work separately?
Your controller is using the same parameter :page for each model. Your view then uses that very parameter to set the page for both models in the view. You can define a different parameter to work with each model. ie.
@tasks = @student.tasks.paginate(page: params[:tasks_page], :per_page => 2)
@plans = @student.plans.paginate(page: params[:plans_page], :per_page => 2)
<%= will_paginate @tasks, :param_name => 'tasks_page'%>
<%= will_paginate @plans, :param_name => 'plans_page'%>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With