views:

29

answers:

2
   @users = User.paginate(
                   :page => params[:page], :per_page => 2,  

I would like to return the total number of results. @users.size simply gives me the number of results on a page. If page 1 has 2 users @users.size = 2, going to page 2 with say 1 user @users.size = 1. How can I show the size of all the users?

A: 

You need to call another Active Record model, named count as such:

@count = User.count
jpartogi
Works for me, thanks.
chief
The plugin performs the `count` operation and sets the count to `total_entries` attribute. There is no need to do a second count.
KandadaBoggu
+2  A: 

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.

Corey