vierundsechzig-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2012-Jul-12 10:05 UTC
engines: accessing classes from the hosting-apps lib
I have an engine and can access model-classes of the hosting app without any troubles. But when I try to access classes that are defined in the lib-directory of the hosting app, they are not found and I get a uninitialized constant Redmine where Redmine is a module defined in the lib-directory of the hosting app. The lib-directory has added this dir to the autoload_paths, but the engine does not see them. The documentation (http://api.rubyonrails.org/classes/Rails/Engine.html) here is a litte vague: The Application class adds a couple more paths to this set. And as in your Application, all folders under app are automatically added to the load path. If you have an app/observers folder for example, it will be added by default. but the paths defined as autoload_paths are not added by default?! Is there a way I can get the engine to load the classes in the lib-dir of the hosting app?! thx for any help, stefan -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/jMVWKss3Tt0J. 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-US.
vierundsechzig-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2012-Jul-12 13:46 UTC
Re: engines: accessing classes from the hosting-apps lib
ok, got this one: reason for the trouble was the load-sequence: I tried to include a module from the hosting app inside a class inside my plugin: this fails inside tests, as the plugin-classes are loaded before the rest of the app (or at least, that is my guess): I solved this by including the module only at runtime with a class MyPluginClass def initialize self.class.send :include, ::Redmine::I18n unless self.class.include? ::Redmine::I18n end ... end This gets rid of the direct include-dependency and postpones the include: When the class is loaded for the first time, the include is added - now all classes, even the ones from lib are available. Am Donnerstag, 12. Juli 2012 12:05:08 UTC+2 schrieb vierund...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org:> > I have an engine and can access model-classes of the hosting app without > any troubles. > > But when I try to access classes that are defined in the lib-directory of > the hosting app, they are not found and I get a > > uninitialized constant Redmine > > where Redmine is a module defined in the lib-directory of the hosting app. > The lib-directory has added this dir to the autoload_paths, but the engine > does not see them. The documentation ( > http://api.rubyonrails.org/classes/Rails/Engine.html) here is a litte > vague: > > The Application class adds a couple more paths to this set. And as in > your Application, all folders under app are automatically added to the > load path. If you have an app/observers folder for example, it will be > added by default. > > but the paths defined as autoload_paths are not added by default?! > > Is there a way I can get the engine to load the classes in the lib-dir of > the hosting app?! > > thx for any help, > stefan > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/6sAQjLWB1QcJ. 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-US.