I have a comment model under a micropost. I was wondering if I can paginate this so that 50 comments won't show all at once once the comment button is clicked on the micropost. I am pretty sure this cannot be paginated but is there a way that like facebook, only a certain amount shows and then the user can show more if they please. Currently my code looks like this:
Micropost HTML for the Comment Section
<div id='CommentContainer-<%= micropost.id%>' class='CommentContainer Condensed2'>
<div class='Comment'>
<%= render :partial => "comments/form", :locals => { :micropost => micropost } %>
</div>
<div id='comments'>
<%=render micropost.comments %>
</div>
</div>
When a button above is clicked it shows this section and I would not like 50 comments to show up all at once. All suggestions will be very helpful. Thank you!
@comments = Comment.paginate(:page => params[:page], :per_page => 10)
in your controller <%= will_paginate @comments %>
call and not through :render
and then later through will_paginate
You can also be sure to checkout the railscast on will_paginate although without a pro subscription you may have to watch the outdated version .
I would suggest you to lookup 2 rails gems that are most widely used for pagination on rails
--> will paginate
--> Kaminari
I prefer Kaminari over will paginate because it offers a lot more flexibility than will paginate.
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.