Forum: Ruby on Rails Mountable engine - Problem with autoload_paths

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
48cfa8ad9f21bcf674af8474c33ea254?d=identicon&s=25 wam r. (wam_r)
on 2013-01-07 16:51
(Received via mailing list)
Hi guys,

In my "fooengine" mountable engine, I have subfolders within the app/
models/fooengine folder. For example:
app/models/fooengine/core_models/foo.rb

In order to have these files loaded, I added:
config.autoload_paths += %W(#{config.root}/app/models/fooengine/
core_models)
to lib/fooengine/engine.rb.

But it gives an error:
LoadError: Expected ... to define Foo
and indeed, the fully qualified name is FooengineFoo, not Foo so the
auto loader is lost.

It works if I rename all my model files to fooengine_(model name).rb,
but I guess there probably is a better way.

Do you know?

Thanks a lot!
PJ
48cfa8ad9f21bcf674af8474c33ea254?d=identicon&s=25 wam r. (wam_r)
on 2013-01-10 12:11
(Received via mailing list)
Hi guys,

Answering my own question in case it helps others.

Devise is considered a kind of "reference" Engine, and the way they do
it is in lib/devise.rb, they use autoload for the classes defined in
their lib folder. For instance:

autoload :Delegator,     'devise/delegator'

It worked for me.

Thanks
PJ
This topic is locked and can not be replied to.