Skip to content
lowell edited this page Aug 9, 2010 · 7 revisions

This is a FAQ on a number of common pitfalls seen on the Google group.

First make sure that you have the latest release of will_paginate. Each new release fixes a number of outstanding bugs. Check the installation instructions and see below how to find out which version do you have.

If these tips don’t help and you become sure you’ve found a bug, here is a list of open will_paginate bugs. Check if it’s already been reported and create a new ticket if it’s not (see Report bugs).

I’m not sure if I installed will_paginate correctly in my Rails application.

Read the installation instructions. Your application should either load the gem or have the plugin located in “vendor/plugins/will_paginate/” directory. To see if the library has been loaded, open “script/console” of your app and try the following lines:

>> defined? WillPaginate
>> [].paginate
>> ActiveRecord::Base.respond_to? :paginate

If any of these lines return nil or result in an error, will_paginate is not properly loaded in your app.

I don’t know which version of will_paginate I have.

It’s easy to find out will_paginate version. Open “script/console” of your app and type:

>> require "will_paginate/version"
>> WillPaginate::VERSION::STRING

If “will_paginate/version” doesn’t exist, then you have a very old version of will_paginate and you should upgrade immediately (see Installation).

I’m getting “undefined method `total_pages’” error when rendering in the view!

In newer versions, the `page_count’ method of WillPaginate::Collection class has been renamed to `total_pages’ for consistency. This broke some Sphinx and Ferret plugins for fulltext indexing in Rails because they were emulating WillPaginate::Collection when trying to be “will_paginate compatible”.

If you are indeed using 3rd party code like this, please update your Sphinx (or Ferret) plugin to the latest version or ask on their mailing lists about this error. Otherwise feel free to report this on our mailing list (top).

Not using Sphinx or Ferret but still getting this error? Make sure your action is using #paginate (Post.paginate), and not #find (Post.find).

Pagination works fine until I click on page 2 or further and my URL parameters get lost.

See Simple search for explanation of why this happens.

Pagination seems to return the same result set regardless of page number.

First inspect the URL. Let’s say that it looks like this:

http://example.com/posts?page=2

You can see that the default name for the page parameter in the URL is, unsurprisingly, “page”. You have to make sure that, in your controller, you pass that parameter to the paginating finder:

@posts = Post.paginate :page => params[:page], :order => 'created_at DESC'

If a wrong parameter is passed as :page parameter, pagination will forever be “stuck” on page 1.

Clone this wiki locally