# Count results of a query?

**URL:** <https://www.ruby-forum.com/t/count-results-of-a-query/130522>\
**Category:** Ruby\
**Created:** [February 28, 2008, 11:56pm UTC](https://www.ruby-forum.com/t/count-results-of-a-query/130522 "2008-02-28T23:56:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![laredotornado](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9dc877/32.png) [@laredotornado](https://www.ruby-forum.com/u/laredotornado)\
**Post date:** [February 28, 2008, 11:56pm UTC](https://www.ruby-forum.com/t/count-results-of-a-query/130522/1 "2008-02-28T23:56:39Z")

</div>

Hi,

I have this code

@users = find(:all, :conditions =\> conditions, :page =\> {:size =\>  
page\_size, :current =\> page\_num} )  
if (@users.count == 0)  
flash[:notice] = “No results found.”  
render :action =\> ‘search’  
end

but as many of you can guess, it gives me a “undefined method: count”  
error. Same if I try “length”. What is the right way to count the  
results of the query? - Dave

---

<div class="post-metadata">

**Author:** ![laredotornado](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9dc877/32.png) [@laredotornado](https://www.ruby-forum.com/u/laredotornado)\
**Post date:** [February 29, 2008, 12:42am UTC](https://www.ruby-forum.com/t/count-results-of-a-query/130522/2 "2008-02-29T00:42:24Z")

</div>

laredotornado wrote:

> Hi,
> 
> I have this code
> 
> @users = find(:all, :conditions =\> conditions, :page =\> {:size =\>  
> page\_size, :current =\> page\_num} )  
> if (@users.count == 0)  
> flash[:notice] = “No results found.”  
> render :action =\> ‘search’  
> end
> 
> but as many of you can guess, it gives me a “undefined method: count”  
> error. Same if I try “length”. What is the right way to count the  
> results of the query? - Dave

@users.size

In the future, simply open up irb and type the following  
@users.methods - Object.instance\_methods

hth

ilan
