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:renderand then later throughwill_paginateYou can also be sure to checkout the railscast on will_paginate although without a pro subscription you may have to watch the outdated version.