Resultset empty?

Hello people,

still a newbie and just wanted to know how to actually test if
resultset from find method is empty or net.

Regards,

Joel

cherring wrote:

Your variable will be nil.

EG

@accounts = Account.find(:all)

if there are no records @account will be nil.

if @accounts.blank?

else

end

On 24 May 2008, at 14:00, cherring wrote:

Your variable will be nil.

EG

@accounts = Account.find(:all)

Wrong. find :all returns an empty array (which you could test with
foo.empty? ). find :first (or things like find_by_xxx) return nil (and
find(xxx) raises ActiveRecord::RecordNotFound if there is no record
with that id)

Fred

Ooops my mistake, live and learn, woot now I know more than before.

On May 25, 8:45 am, Frederick C. [email protected]

Your variable will be nil.

EG

@accounts = Account.find(:all)

if there are no records @account will be nil.