Count records returned by find ?

I just want to create a simple “no records returned” -
using this statement though

@positions = pq.find
if @positions.count < 1

“undefined method `count’ for #Array:0x4b0adc8

I’m not looking to apply any conditions only total records returned by the find.

Anyway tell me what I’m doing wrong ?

You can do...

"Nothing found" unless @positions.empty?
"Nothing found" if @positions.size == 0


You can also use count_by_sql for just counting the results. Here is
an example:

Gift.count_by_sql("select count(distinct url) from gifts")

It can be any sql statement that returns a count().


Thanks guys (Kevin and Tom)

I went with @positions.size and that works good.
However , and this might be another thread all together I’m noticing a little freaky behaviour.
This is an ajax form taking user conditions -
what I’m finding is the first time it hits a condition that returns no records it won’t say no records found.

if I go back , clear the condition and put it in again , then it will.

Sound weird ?