Here's a brand new Rails 5.1.4 app, with a model and a couple of routes and controllers.
A namespaced controller is referencing a top level model:
class AdminArea::WelcomeController < ApplicationController
def index
@user = User.new(name: 'Sergio')
end
end
So far so good. You can check out the master, navigate to http://localhost:3000/admin_area/welcome
and see it work.
BUT if we were to add an empty directory app/presenters/admin_area/user/
*, then things get weird. All of a sudden, User
in that controller is not my model, but a non-existing module!
NoMethodError (undefined method `new' for AdminArea::User:Module):
app/controllers/admin_area/welcome_controller.rb:3:in `index'
Naturally, this module doesn't have any [non-built-in] methods and can't be pinned to a source file on disk.
Question: why adding an empty directory causes rails to mysteriously conjure a module out of thin air instead of correctly resolving name User
to my model?
* actually, if you check out that branch as-is, you'll get a different error.
NameError (uninitialized constant AdminArea::WelcomeController::User)
because git wouldn't let me commit an empty directory, so I added a .keep
file in there. But as soon as you delete that file, you get the behaviour described above.