3

I have a namespaced route and here's how I created the controller:

module A
  module B
    module Test
      class DummyController < ApplicationController

        def quantify_stocks
          something = Test::Dummy::Something.new(params)

          # more code here
        end
      end
    end
  end
end

I am trying to access the class Test::Dummy::Something but it autoloads the constant Test with A and B (A::B::Test)?

The error I get is:

NameError (uninitialized constant A::B::Test::Dummy)

1 Answer 1

5

Try ::Test::Dummy::Something

Test in this context will always refer to A::B::Test so you need to say explicitly that you need Test from the global namespace, which is exactly what ::Test does

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! This is what I was looking for :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.