1

I am using a Rails Engine as a Gem in my Rails Application. Now I have inherited a class from the rails engine in a model of my rails app.

1. Rails App Model Code

class AppModelOne < EngineGem::EngineClassOne
   # body of the class
end

But while running the command
rake zeitwerk:check
in terminal, I got a error that
uninitialised constant <class:32323332xx> EngineModuleTwo
Now I checked the rails engine code of EngineClassOne in which there is a include statement of EngineModuleTwo.

2. Rails Engine Class Code

module EngineGem
  class EngineClassOne
     include EngineModuleTwo::EngineSubModuleOne
  end
end

The Engine file-structure:

  EngineGem -> |-> app     -> models |-> engine_gem         -> engine_class_one
               |                     |-> engine_module_two  -> engine_sub_module_one
               |-> gemspec

Why it is not able to load the module, Can anyone explain how to load the module inside the rails engine while using it in my rails app?

Supriyo Mahanta
  • 233
  • 1
  • 3
  • 11
  • `include` is used to mix the contents of a module into a class. You can't use `include` when the target is another class. If `EngineClassTwo` is indeed a class, that's an error and zeitwerk will complain. – rmlockerd Jul 08 '21 at 18:16
  • You can see this if you run a rails console in the engine gem. Instantiating an instance of `EngineGem::EngineClassOne` will raise an error. – rmlockerd Jul 08 '21 at 18:18
  • By default we can't open a rails console in engine right @rmlockerd – Supriyo Mahanta Jul 09 '21 at 05:08
  • Yes @rmlockerd , Inside EngineClassOne I am including a module , I have updated the question, Kindly have a look, and suggest any solution. – Supriyo Mahanta Jul 09 '21 at 05:24
  • I can't reproduce your error as you have it specified now. What options did you use to create your engine? `--full`? – rmlockerd Jul 09 '21 at 05:37
  • @rmlockerd I am using a existing engine made by someone else. Can you specify any settings/config which will help you out to identify. – Supriyo Mahanta Jul 09 '21 at 05:41

0 Answers0