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

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   has_many :invoices   has_one :user

  def self.get_invoices     invoices.find(:all)   end end

class User < ActiveRecord::Base   belongs_to :Provider   belongs_to :Consumer

  def invoices_raised     Provider.get_invoices   end

   ...

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

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    has_many :invoices    has_one :user end

class User < ActiveRecord::Base    belongs_to :provider # Note the lower case here    belongs_to :consumer    has_many :invoices, :through => :provider

   ... end

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

Cheers,

Pete Yandell