Victor Tanvuia
2012-Jun-07 15:26 UTC
load_missing_constant: Expected to define class in module
Hi I''m having some weird issues with Rails 3 and classes defined in modules. To be more precise I''ve created several files that define classes in the AppBase module like: module AppBase class BackendMenu [content omitted] end end When a page tries to use the BackendMenu class like AppBase::BackendMenu I get an error saying "Expected backend_menu.rb to define BackendMenu (load error)", but if reload the page the error no longer displays and the application works as it''s supposed to. The same thing happens to all the other files. Basically I need to reload the page for each class I''m using, but after they''ve all been loaded everything works. Have you any ideas why I get this behavior and how to fix it? The main problem is that if I use one of the classes in the initializers I can''t force a reload and the application won''t start. -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2012-Jun-07 18:49 UTC
Re: load_missing_constant: Expected to define class in module
On Jun 7, 4:26 pm, Victor Tanvuia <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi I''m having some weird issues with Rails 3 and classes defined in > modules. > > To be more precise I''ve created several files that define classes in the > AppBase module like: > module AppBase > class BackendMenu > [content omitted] > end > endRails'' magic code loading would expect this file to be in app_base/ backend_menu.rb app_base.rb should define the AppBase module (possibly empty). Have you tried that? Fred.> > When a page tries to use the BackendMenu class like AppBase::BackendMenu > I get an error saying "Expected backend_menu.rb to define BackendMenu > (load error)", but if reload the page the error no longer displays and > the application works as it''s supposed to. > > The same thing happens to all the other files. Basically I need to > reload the page for each class I''m using, but after they''ve all been > loaded everything works. > > Have you any ideas why I get this behavior and how to fix it? > > The main problem is that if I use one of the classes in the initializers > I can''t force a reload and the application won''t start. > > -- > Posted viahttp://www.ruby-forum.com/.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Victor Tanvuia
2012-Jun-07 19:08 UTC
Re: load_missing_constant: Expected to define class in module
Frederick Cheung wrote in post #1063594:> On Jun 7, 4:26pm, Victor Tanvuia <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Hi I''m having some weird issues with Rails 3 and classes defined in >> modules. >> >> To be more precise I''ve created several files that define classes in the >> AppBase module like: >> module AppBase >> class BackendMenu >> [content omitted] >> end >> end > > Rails'' magic code loading would expect this file to be in app_base/ > backend_menu.rb > app_base.rb should define the AppBase module (possibly empty). Have > you tried that? > > Fred.Hurrah, It works. The files were in the appbase folder so that''s what the problem was. Forgot to add the underscore. Many thanks. -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.