Question

At the same page I have projects list on the right and comments feed to the left side of the page.

Will_paginate limits 10 comments per page

Controller:

def index
  @projects = Project.paginate(page: params[:page], per_page: 10)
  @comments = Comment.paginate(page: params[:page], per_page: 10)
end

View:

%table.table
  %tbody
  - @comments.each do |comment|
    %tr
      %td.feeds
        %li #{comment.content}
        %span.proj_title #{link_to comment.project.title, comment.project}
        %br
        %span.timestamp Posted at #{comment.created_at}.
= will_paginate @comments

When Comments.count > 10 and I trigger second page on paginator, request changes from

http://0.0.0.0:3000/projects?page=1 

to

http://0.0.0.0:3000/projects?page=2 

so it changes pages. And right side(projects list) dissapears.

How prevent that from happening and render pagination correctly?

Was it helpful?

Solution

In your implementation, params[:page] applies for both paginations.

You must provide a custom pagination parameter for either list, so each will have its own parameter.

So, for example:

In your view, you will have two paginations:

= will_paginate @comments

and

= will_paginate @projects, :param_name => "pr_page"

So, in your controller:

def index
  @projects = Project.paginate(page: params[:pr_page], per_page: 10)
  @comments = Comment.paginate(page: params[:page], per_page: 10)
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top