I Will Paginate, my dear!
- Published January 23rd, 2008 in Tips & Tricks, Ruby
Goodbye Pagination, Welcome I Will Paginate!
Rails 2.0 dropped the pagination helper from the framework with the intent of being replaced by the will paginate plugin. Cool thing is, the plugin is also available to 1.2.x. Whether you're still holding on to Rails 1.2.x or you did the upgrade, will_paginate plugin is the way to go for paginating.
So, what's the difference between Rails Pagination and will_paginate plugin?
First off, the syntax is the same as Model.find. Actually, Model.paginate encapsulates a find call, so you're at home here. Take a look
-
@posts = Post.paginate :all, :conditions => "no_comments> 5", :order => "created_at DESC", :per_page => 5
Is this all? Not at all. Remember having to deal with a @posts_pages collection containing the pages? Forget about that. Here's what you have to do from now on within your views:
-
<%= will_paginate @posts [, options] %>
Isn't this insanely great? Full blown pagination with 2 lines of code. If you're still looking for juice, don't miss this UI design pattern from Yahoo on how to properly use pagination.




No Responses to “I Will Paginate, my dear!”