show array size with will_paginate
I would like to retur开发者_StackOverflown 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?
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.
You need to call another Active Record model, named count as such:
@count = User.count
精彩评论