Search code examples
ruby-on-railsrubyrails-engines

Rails mountable engines helper methods not found when routing from main app


I have a module as a mountable engine mounted to a main app through

mount MyEngine::Engine, :at => '/myengine'

I have everything namespaced in the negine and the engine has it's own views in engine/app/views/myengine/

Everything works fine when I run rails server then try to access

localhost:3000/myengine

first then go to the root of the main app and come back to the engine through a link in the index view of the main app

However when I start the server, go to localhost:3000 and from there click on the link to the engine module it tries to fetch the views correctly however the methods contained in the engine's helpers raises an error upon call for them being undefined.

I am on rails 4


Solution

  • I used eager_load to load the mountable engine in it's initialized in the main app and everything seems to be working now.

    Myengine::Engine.eager_load!