paginating_find plug-in
After looking around for an alternative to the inbuilt rails pagination I found the paginating_find plug-in by Alex Wolfe of cardboardrocket.com.There were 2 reasons I wanted an alternative to the pagination that comes with rails. 1) The inbuilt pagination only allows you to go to the next or previous page which can be a pain when you have lots of pages 2) Pagination will be extracted out into a plug-in in Rails 2.0.
So after trying to find a simple solution to my problem I came across the pagination_find plug-in, which I found very easy to get working and produces page numbers that allow you to skip to specific pages.
Here’s how I used it on this website.
First I installed the plug-in, by opening a ruby console window, going to the rails apps I wanted to install the plug-in on and running this command.
ruby script/plugin install http://svn.cardboardrocket.com/paginating_find
Then I went to the blog controller (app/controller/blog.rb) and replaced the old pagination code in the index action with the new pagination code.
def index
@post_pages, @posts = paginate :posts, :order => "created_at DESC", :per_page => 4
end
def index
@posts = Post.find(:all, :order, => "created_at DESC", :page => {:size => 5, :current => params[:page]})
end
Next thing was to change my index.rhtml view (app/views/blog/index.rhtml) to display the pages with the pagination links.
<% @posts.each do |post| %>
#Code for displaying posts
<% end %>
<%= paginating_links(@posts) %>
And thats all there is to it, for more options go to the pagination_find website.
One more thing, if you get a “Unknown key(s): page” error,it’s because you haven’t restarted your server after installing the plug-in.



Leave a Reply