Stuart Grimshaw
2006-Nov-07 23:44 UTC
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Stuart Grimshaw
2006-Nov-08 00:05 UTC
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Pete Yandell
2006-Nov-20 23:03 UTC
Re: undefined local variable or method `invoices'' for Provider:Class
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 On 08/11/2006, at 10:44 AM, Stuart Grimshaw wrote:> > 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 > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---