# Undefined method exception if no data is present

**URL:** <https://www.ruby-forum.com/t/undefined-method-exception-if-no-data-is-present/135007>\
**Category:** Rails\
**Created:** [April 17, 2008, 12:40am UTC](https://www.ruby-forum.com/t/undefined-method-exception-if-no-data-is-present/135007 "2008-04-17T00:40:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [April 17, 2008, 12:40am UTC](https://www.ruby-forum.com/t/undefined-method-exception-if-no-data-is-present/135007/1 "2008-04-17T00:40:36Z")

</div>

I get this error if no relational data is present:  
undefined method `notes’ for #Array:0x226cc4c

Here is the code that causes the error:  
@notes = @account.notes

If I call this method through the script/console I get  
account = Account.find(3)  
=\> #\<Account id: 3, …\>

> > account.notes  
> > =\> []

I get the same error if I don’t declare the @notes var and access the  
notes collection through the controller within the haml template ie  
@account.notes.each do |n| …

I am puzzled.

Thanks for the help

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [April 17, 2008, 2:04am UTC](https://www.ruby-forum.com/t/undefined-method-exception-if-no-data-is-present/135007/2 "2008-04-17T02:04:09Z")

</div>

It looks like your trying to call a notes method on an instance of an  
Array. I don’t think Arrays have a notes method.

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [April 17, 2008, 2:17am UTC](https://www.ruby-forum.com/t/undefined-method-exception-if-no-data-is-present/135007/3 "2008-04-17T02:17:28Z")

</div>

Right you are. It was a mistype of :all rather than :first in the  
lookup.

Thanks
