I want to pull 5 records at a time into the view (I’m using rails 2.3.8).
I am using will_paginate, and it’s working great but:
I want to send those results to the view, 5 records at a time, then add a div, then loop through until they’re all shown.
I tried using find_in_batches, but I don’t know how to access the objects it’s returning. Can I use #{}?
I know there’s .first and .last methods but is there any such thing as .second, .third, .fourth, etc?
You have an example for
find_in_batchesin the documentation:This may not be the solution you’re looking for, though. If you have 5000 records, this will issue 1000 database queries.
A better solution would be using
each_slice, this method will fetch all records in one database query and split the result set afterwards: