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

Your variable will be nil.

EG

@accounts = Account.find(:all)

if there are no records @account will be nil.

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

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.