# undefined local variable or method \`invoices' for Provider:Class

**URL:** <https://discuss.rubyonrails.org/t/undefined-local-variable-or-method-invoices-for-provider-class/4205>\
**Category:** rubyonrails-talk\
**Created:** [November 7, 2006, 11:44pm UTC](https://discuss.rubyonrails.org/t/undefined-local-variable-or-method-invoices-for-provider-class/4205 "2006-11-07T23:44:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stuart\_Grimshaw](https://avatars.discourse-cdn.com/v4/letter/s/ec9cab/32.png) [@Stuart\_Grimshaw](https://discuss.rubyonrails.org/u/Stuart_Grimshaw)\
**Post date:** [November 7, 2006, 11:44pm UTC](https://discuss.rubyonrails.org/t/undefined-local-variable-or-method-invoices-for-provider-class/4205/1 "2006-11-07T23:44:06Z")

</div>

I'm pretty new to Rails, and I think my app has progressed quicker than my knowledge of Rails/Ruby has ...

I have the following models:

[-- Begin --] class Provider \< ActiveRecord::Base &nbsp;&nbsp;has\_many :invoices &nbsp;&nbsp;has\_one :user

&nbsp;&nbsp;def self.get\_invoices &nbsp;&nbsp;&nbsp;&nbsp;invoices.find(:all) &nbsp;&nbsp;end end

class User \< ActiveRecord::Base &nbsp;&nbsp;belongs\_to :Provider &nbsp;&nbsp;belongs\_to :Consumer

&nbsp;&nbsp;def invoices\_raised &nbsp;&nbsp;&nbsp;&nbsp;Provider.get\_invoices &nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;...

end [-- End --]

and when I call User.invoices\_raised I get this error:

undefined local variable or method `invoices' for Provider:Class

Now I thought that having the "has\_many :invoices" line would automatically make the connection and let me access "invoices" like that, but obviously I'm wrong. Anyone care to correct me?

Cheers,

-S

---

<div class="post-metadata">

**Author:** ![Pete\_Yandell](https://avatars.discourse-cdn.com/v4/letter/p/a183cd/32.png) [@Pete\_Yandell](https://discuss.rubyonrails.org/u/Pete_Yandell)\
**Post date:** [November 20, 2006, 11:03pm UTC](https://discuss.rubyonrails.org/t/undefined-local-variable-or-method-invoices-for-provider-class/4205/2 "2006-11-20T23:03:58Z")

</div>

I'm not sure what you're trying to do here, but you're clearly  
getting classes and instances confused. I think what you meant to do  
is this:

class Provider \< ActiveRecord::Base &nbsp;&nbsp;&nbsp;has\_many :invoices &nbsp;&nbsp;&nbsp;has\_one :user end

class User \< ActiveRecord::Base &nbsp;&nbsp;&nbsp;belongs\_to :provider # Note the lower case here &nbsp;&nbsp;&nbsp;belongs\_to :consumer &nbsp;&nbsp;&nbsp;has\_many :invoices, :through =\> :provider

&nbsp;&nbsp;&nbsp;... end

Then you can just call user.invoices for a particular user.

Cheers,

Pete Yandell
