Search code examples
ruby-on-railswill-paginate

will_paginate gem not working


I'm having a problem with will_paginate that's pretty simple to express:

> Story.paginate(page: 1, per_page: 10).count
=> 20

Obviously, that number should be 10, not 20.

Am I somehow doing something wrong? Doesn't seem like there's much room for error here, but obviously something isn't right. What am I missing?


Solution

  • You want Story.paginate(page: 1, per_page:10).size, not count. Count will actually return the total numbers of records generated by your query.