Reputation: 11
I would like to return the total number of results from this query:
@users = User.paginate(:page => params[:page], :per_page => 2)
@users.size
simply gives me the number of results on a page. If page 1 has 2 users, then @users.size
will be 2. If page 2 has 1 user, then @users.size
will be 1.
How can I show the size of all the users?
Upvotes: 1
Views: 752
Reputation: 2243
will_paginate adds some attributes to the returned collection one of them is total_entries
which is the total number of results the query would have returned.
Upvotes: 8
Reputation: 16425
You need to call another Active Record model, named count as such:
@count = User.count
Upvotes: -3