I have several modules that I store in rails_root/lib and that are used by my controllers. I''m having a problem accessing AR objects from inside a class that is a subclass. I keep getting a NameError when trying to do something like Foo.find(), where Foo is an AR object. uninitialized constant OpenTransact::Gateway::Request::CreditCardCharge::PaymentAccount (NameError) For some reason the namespace has changed inside my class instance (an instance of CreditCardCharge) so that the AR object PaymentAccount is no longer there. If I access PaymentAccount from a class instance that is not a subclass, it works fine. What am I missing? Chris --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
apsoto-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Feb-19 21:58 UTC
Re: namespaces in subclasses
Hey there, Only thing that come''s to mind is that the object your trying to access hasn''t been ''require''-ed, hence the ''unitialized constant'' error. You might want to try the debugger <http://www.datanoise.com/ ruby-debug> and step into the code to see where the error occurs. Once you step through the code I''m sure you''ll have an ah-ha moment where the error will make sense. I hope you find something that will let you work around the problem. I haven''t tried namespaced models, so not sure if you''ll find a fix. On Feb 18, 3:47 pm, snacktime <snackt...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have several modules that I store in rails_root/lib and that are > used by my controllers. I''m having a problem accessing AR objects > from inside a class that is a subclass. I keep getting a NameError > when trying to do something like Foo.find(), where Foo is an AR > object. > > uninitialized constant > OpenTransact::Gateway::Request::CreditCardCharge::PaymentAccount > (NameError) > > For some reason the namespace has changed inside my class instance (an > instance of CreditCardCharge) so that the AR object PaymentAccount is > no longer there. If I access PaymentAccount from a class instance > that is not a subclass, it works fine. What am I missing? > > Chris--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---