views:

200

answers:

1

I am creating a Will_Paginate::Collection object using the following code

@paginatedResults = WillPaginate::Collection.new(1, 5)
@paginatedResults.replace @results[@paginatedResults.offset, 
                                   @paginatedResults.per_page]

but when I try to render the pagination using

<%= will_paginate @paginatedResults %>

I get an exception

You have a nil object when you didn't expect it!
The error occurred while evaluating nil.>

I have traced it back to the total_entries property on the Will_Paginate::Collections object. The property is missing. I don't know why.

Any ideas?

+1  A: 

You have to do the count manually if you use new to create it, from the API docs:

new (page, per_page, total = nil)

Arguments to the constructor are the current page number, per-page limit and the total number of entries. The last argument is optional because it is best to do lazy counting; in other words, count conditionally after populating the collection using the replace method.

MattMcKnight