-
Notifications
You must be signed in to change notification settings - Fork 0
Troubleshooting
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 compatible with your Rails version. Each new release fixes a number of 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, see Report bugs.
Your application should either load the will_paginate gem or have the plugin located in “vendor/plugins/will_paginate/” directory. To see if the library has been loaded, open the console for your app and try the following lines:
>> defined? WillPaginate
>> ActiveRecord::Base.respond_to? :paginate
If any of these lines return nil/false
, will_paginate has not properly loaded in your app.
It’s possible that you are trying to paginate a static Array instead of performing a paginated query in the database. For instance, chaining a paginate
call after an Active Record find
or all
methods is wrong:
# this is wrong:
Post.find(:conditions => '...').paginate(:page => 1)
The above line will return the desired result but defeats the purpose of pagination. Here, the find
query will first load all the records from the database, which is dangerous and should be avoided.
If you know what you’re doing and really need to paginate Arrays, require this feature explicitly:
require 'will_paginate/array'
It’s easy to find out the current version. Open the console for 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.
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 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.
Not using Sphinx or Ferret but still getting this error? Make sure you’re passing a paginated collection to the will_paginate helper, not an ordinary array.
See Simple search for explanation of how this might happen.
First inspect the URL. Let’s say that it looks like this:
http://example.com/posts?page=2
The default name for the page parameter in the URL is “page”. You have to make sure that, in your controller, you pass that same parameter to the paginating finder:
@posts = Post.paginate :page => params[:page]
If a wrong parameter is passed as :page
parameter, pagination will forever be “stuck” on page 1.
- Installation instructions
- API documentation
- Differences between v2.3 - v3.0
- Troubleshooting or Report bugs
- Simple search functionality
- Translating output (i18n)
- Join the Google group
- Browse the source code
- See the recent commits