Paginate an array using will_paginate

The will_paginate gem is a great bit of kit for adding pagination to your larger result sets. I recently had some trouble getting will_paginate to paginate an array. Naturally I checked the will_paginate Github page but failed to see a small entry in the wiki here (frankly I’ve never been a huge fan of the wiki on Github).

Next I went on to search “will_paginate array”. This got loads of results, most of which were completely useless as none seemed to specify the most important and only bit of information I needed.

So if you get an error message similar to “undefined method `paginate’ for #<Array:0x7be49dc> ” then try adding the line below to your controller.

require 'will_paginate/array'
Advertisements
This entry was posted in Programming, Ruby on Rails and tagged , , , . Bookmark the permalink.

4 Responses to Paginate an array using will_paginate

  1. Ray says:

    Thank you for your post, I was almost literally pulling out my hair trying to figure this out as well. Why the didn’t just post this little tip in the ACTUAL documentation is beyond me.

  2. soundarapandian says:

    Hi, i have been searching for this.It helped me to fix the issue.Thanks for your post 🙂

  3. HY ChanHan says:

    Thank you very much for your post. It is really helpful for whom newer to rails.

  4. DrNick says:

    Thank you! That’s been driving me mad for a while now! 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s