0

I have an app directory in my Rails 7 App, app/beer, and in that folder a file named cool.rb with a defined method execute.

So in an ActiveJob DrinkSudsJob perform method I am calling a method execute from cool.rb as:

def perform
  Beer::Cool.execute
end

But my App blows up. Tells me unitialized constant DrinkSudsJob::Beer

Zeitwerk:check tells me everything is fine. What am I doing wrong here?

bin/rails r 'puts ActiveSupport::Dependencies.autoload_paths'
/Users/sputz/Documents/Workspace/Apps/2022/fug/app/beer
David Lazar
  • 10,865
  • 3
  • 25
  • 38

1 Answers1

1

If zeitwerk:check passes and app/beer is in the autoload paths, then app/beer/cool.rb defines (and has to define) Cool, not Beer::Cool.

Xavier Noria
  • 1,640
  • 1
  • 8
  • 10
  • I agree. But in this App there was another module that defined an autoloaded whisky/cool.rb, and it was missing the method execute. So calling Cool.execute failed. So I tried Beer::Cool.execute, which failed. I now understand how to organize this better. I have /app/drinks/beer/cool.rb and that is different from /app/drink/whisky/cool.rb and so now I can reference Beer::Cool.execute() fine as opposed to Whisky::Cool.drink() – David Lazar Feb 25 '22 at 20:21
  • Exactly, that structure seems to match your use case . – Xavier Noria Feb 26 '22 at 10:06