In my /lib directory, I have: /my_module/my_code and inside lives my_class.rb: module MyModule::MyCode class MyClass < ActiveRecord::Base def foo end end end I would like to be able to access the MyClass class in my controller via: MyCode::MyClass.foo I was under the impression this was possible by including the MyModule module in application.rb but it doesn''t work. The only way I can access the MyClass class is via MyModule::MyCode.MyClass.foo which is a mouthful. Any ideas?? Thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
After including the file, If you type in: @foo = MyClass.new What error do you get? Does it suggest that it doesn''t exist? Zach Inglis → Blog -- http://www.zachinglis.com → Company -- http://www.lt3media.com → Portfolio -- http://portfolio.zachinglis.com On May 24, 2007, at 11:42 AM, Rich Brant wrote:> > In my /lib directory, I have: > > /my_module/my_code > > and inside lives my_class.rb: > > > module MyModule::MyCode > > class MyClass < ActiveRecord::Base > > def foo > end > > end > > end > > > I would like to be able to access the MyClass class in my > controller via: > > MyCode::MyClass.foo > > I was under the impression this was possible by including the MyModule > module in application.rb but it doesn''t work. The only way I can > access the MyClass class is via MyModule::MyCode.MyClass.foo which is > a mouthful. > > Any ideas?? > > Thanks! > > >--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
yeah, now matter what I try I get uninitialized constant errors, which seems so strange. If I use the full path, it''s fine, but mixing in the module doesn''t give me access to the class. On 5/25/07, Zach Inglis // LT3media <lists-w8tEHcFK2X5Wk0Htik3J/w@public.gmane.org> wrote:> > After including the file, > If you type in: > @foo = MyClass.new > > What error do you get? Does it suggest that it doesn''t exist? > > Zach Inglis > → Blog -- http://www.zachinglis.com > → Company -- http://www.lt3media.com > → Portfolio -- http://portfolio.zachinglis.com > > > On May 24, 2007, at 11:42 AM, Rich Brant wrote: > > > > > In my /lib directory, I have: > > > > /my_module/my_code > > > > and inside lives my_class.rb: > > > > > > module MyModule::MyCode > > > > class MyClass < ActiveRecord::Base > > > > def foo > > end > > > > end > > > > end > > > > > > I would like to be able to access the MyClass class in my > > controller via: > > > > MyCode::MyClass.foo > > > > I was under the impression this was possible by including the MyModule > > module in application.rb but it doesn''t work. The only way I can > > access the MyClass class is via MyModule::MyCode.MyClass.foo which is > > a mouthful. > > > > Any ideas?? > > > > Thanks! > > > > > > > > > >-- Rich Brant Senior Developer Mediagistics, LLC Tel: (215) 674-4515 Mobile: (267) 640-2195 Email: rbrant-LzjNElC0yZQ5ffrT631h+Q@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---