# NoMethodError: undefined method \`expenses'

**URL:** <https://www.ruby-forum.com/t/nomethoderror-undefined-method-expenses/158897>\
**Category:** Rails\
**Created:** [January 29, 2009, 6:22am UTC](https://www.ruby-forum.com/t/nomethoderror-undefined-method-expenses/158897 "2009-01-29T06:22:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arjackson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/57b2e6/32.png) [@arjackson](https://www.ruby-forum.com/u/arjackson)\
**Post date:** [January 29, 2009, 6:22am UTC](https://www.ruby-forum.com/t/nomethoderror-undefined-method-expenses/158897/1 "2009-01-29T06:22:00Z")

</div>

Hi,  
I am trying to figure out why I am receiving the following error. I am  
following an Apple Developers Rail Application tutorial.

> > event.expenses.create(:vendor =\> vendor1, :amount =\>75.00)  
> > NameError: undefined local variable or method `vendor1’ for  
> > #Object:0x389a0  
> > from (irb):2

Here is what I have for the models

class Event \< ActiveRecord::Base  
validates\_presence\_of :name  
validates\_numericality\_of :budget, :greater\_than =\> 0.0

has\_many :expenses  
has\_many :vendors, :through =\> :expenses  
end

* * *

class Expense \< ActiveRecord::Base  
belongs\_to :event  
belongs\_to :vendor  
end

* * *

class Vendor \< ActiveRecord::Base  
has\_many :expenses  
has\_many :events, :through =\> :expenses  
end

I read another post where they had issues with Xcode not saving and  
having to restart terminal. I have done both and everything looks  
right.  
Thanks in advance for any help!

---

<div class="post-metadata">

**Author:** ![arjackson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/57b2e6/32.png) [@arjackson](https://www.ruby-forum.com/u/arjackson)\
**Post date:** [January 29, 2009, 7:50am UTC](https://www.ruby-forum.com/t/nomethoderror-undefined-method-expenses/158897/2 "2009-01-29T07:50:53Z")

</div>

UMQ: Use More Quotes!

:vendor =\> “vendor1”, :amount =\> “75.00”

On Jan 28, 9:22 pm, Andrew R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![arjackson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/57b2e6/32.png) [@arjackson](https://www.ruby-forum.com/u/arjackson)\
**Post date:** [January 29, 2009, 12:47pm UTC](https://www.ruby-forum.com/t/nomethoderror-undefined-method-expenses/158897/3 "2009-01-29T12:47:58Z")

</div>

Link? The reason is you’re using a temporary variable you haven’t set  
to any value before you’re using it. You probably want a string  
‘vendor1’ rather than vendor1 which is a temp variable.

Sent from my iPhone

On 29/01/2009, at 4:22 PM, Andrew R. \<rails-mailing-list@andreas-
