ruby on rails - will_paginate ajax pagination error -


at same page have projects list on right , comments feed left side of 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 |comment|     %tr       %td.feeds         %li #{comment.content}         %span.proj_title #{link_to comment.project.title, comment.project}         %br         %span.timestamp posted @ #{comment.created_at}. = will_paginate @comments 

when comments.count > 10 , 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 changes pages. , right side(projects list) dissapears.

how prevent happening , render pagination correctly?

in implementation, params[:page] applies both paginations.

you must provide custom pagination parameter either list, each have own parameter.

so, example:

in view, have 2 paginations:

= will_paginate @comments 

and

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

so, in controller:

def index   @projects = project.paginate(page: params[:pr_page], per_page: 10)   @comments = comment.paginate(page: params[:page], per_page: 10) end 

Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -