# Resultset empty?

**URL:** <https://www.ruby-forum.com/t/resultset-empty/138529>\
**Category:** Rails\
**Created:** [May 24, 2008, 2:43am UTC](https://www.ruby-forum.com/t/resultset-empty/138529 "2008-05-24T02:43:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![joel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9bd4f/32.png) [@joel](https://www.ruby-forum.com/u/joel)\
**Post date:** [May 24, 2008, 2:43am UTC](https://www.ruby-forum.com/t/resultset-empty/138529/1 "2008-05-24T02:43:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9bd4f/32.png) [@joel](https://www.ruby-forum.com/u/joel)\
**Post date:** [May 25, 2008, 12:45am UTC](https://www.ruby-forum.com/t/resultset-empty/138529/2 "2008-05-25T00:45:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9bd4f/32.png) [@joel](https://www.ruby-forum.com/u/joel)\
**Post date:** [May 25, 2008, 12:46am UTC](https://www.ruby-forum.com/t/resultset-empty/138529/3 "2008-05-25T00:46:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9bd4f/32.png) [@joel](https://www.ruby-forum.com/u/joel)\
**Post date:** [May 25, 2008, 10:21am UTC](https://www.ruby-forum.com/t/resultset-empty/138529/4 "2008-05-25T10:21:36Z")

</div>

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

On May 25, 8:45 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![joel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9bd4f/32.png) [@joel](https://www.ruby-forum.com/u/joel)\
**Post date:** [May 25, 2008, 12:41am UTC](https://www.ruby-forum.com/t/resultset-empty/138529/5 "2008-05-25T00:41:39Z")

</div>

Your variable will be nil.

EG

@accounts = Account.find(:all)

if there are no records @account will be nil.
