I am building a Rails Engine. I defined a controller like this,
module A::B::C::D::E
extend ActiveSupport::Concern
# module stuff ...
end
class ExamplesController < ApplicationController
include A::B::C::D::E
# controller stuff ...
end
When I start the Rails console, rails console, I get the following error,
uninitialized constant A::B (NameError)
Why do I get this error?
Because the module does not exist at the point you are using it.
Since
Ais not defined, Ruby doesn’t know what it is.Note that the
::is a scope resolution operator used for look up, not defining a namespace-like hierarchy.It would work if you defined
Afirst:Then
B:Then
C:And so on.
Of course you could also do this: