Tuesday, October 4, 2011

Paginate an array using will_paginate

Paginate an array using will_paginate

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 # ” then try adding the line below to your controller.

1
require 'will_paginate/array'