will_paginate: undefined method `total_pages' for #

Hi Mislav, I got error in my project with will_paginate, i used rails 4 , active record 4, and will_paginate 3.0.7

in my controller @users=User.paginate(:page => params[:page], :per_page => 30)

in my view <%= will_paginate @users %>

always give error undefined method `total_pages’ for #User::ActiveRecord_Relation:0x000000051b4608

how to solve it,? Thanks

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 16 (1 by maintainers)

Commits related to this issue

Most upvoted comments

I got this error, too. But I figured out I forgot to use paginate in my controller.

- @users = User.where('email LIKE ?', '%some%')
+ @users = User.where('email LIKE ?', '%some%').paginate(page: params[:page])

Still getting this problem in a new application. Initially I was only getting it with blank results, as had been asserted. But even after populating the database and having an Active Record Relation with multiple entries the same error is being generated. It seems like the Relation is not being handled by will_paginate’s model tweaking for Rails.

The problem for me was that will_paginate in the view is being passed an un-paginated collection

I had a conditional that added pagination

collection = # ...

if some_option?
  collection = ar_relation.page(params[:page])
end

collection

Got rid of my conditional and it’s fine now