Paginating

Published 2008-07-19 by Robert Burén
Tags: blog.rb, feature, pagination, plugin, will_paginate

Ok, Pagination has been in place a few days now, but since I have it set to display ten posts per page, it’ll be a while before it is apparent on this page.

Adding it was simple: installing the will_paginate gem and adding this line of code in Blog#show:

    @posts = @blog.published_posts.paginate :page => params[:page], 
    :per_page => 10

Finally, one line in the view adds the actual pagination UI, if needed:

<%= will_paginate @posts %>
 

No comments posted.
Add comment »