Skip to content

Loading module and namespaced classes from directory structure #38726

@fxn

Description

@fxn

(Moved from fxn/zeitwerk#113, with description edited to reflect that we are talking about directories and files below app/models.)

As someone with a Rails background, I am accustomed for this to work:

# app/models/mymodule.rb
module Mymodule
end
# app/models/mymodule/myclass.rb
module Mymodule
  class Myclass
  end
end

Now that Rails 6 uses Zeitwerk, when trying to autoload Mymodule::Myclass, it stops looking after finding app/models/mymodule.rb, raises a NameError and does not descend into the subfolder anymore.

It works after deleting the empty module file, but that's only possible as long as it remains empty: usually this file is used to override defaults like table name prefixes for classes of the module.

Is it a user error, bug or maybe just a problem of the integration of Zeitwerk into Rails?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions