0

I would like to know what is the right way to use a class with namespace in rails 6. I have the follow, but it isn't working and I'm receiving the error:

"Uninitialized constant ProductsController::Operations Did you mean? ProductsController::Options"

#app/operations/create.rb
module Operations
  class Create
    def self.foo
      ...
    end
  end
end

#app/controllers/products_controller.rb

class ProductsController < ApplicationController
  def create
    Operations::Create.foo
  end
end

Can you help me please?

1
  • The file has to be in app/modules/operations/create.rb. You can swap out modules for really anything you like Commented Nov 19, 2020 at 14:21

1 Answer 1

1

Your module should be inside of any folder. For example app/services/operations/create.rb (any name will work) with the same content you have:

module Operations
  class Create
    def self.foo
      ...
    end
  end
end

and call it Operations::Create.foo.

Also make sure you restart spring with spring stop.

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

1 Comment

Glad to hear that @LuísZambon. Can you accept my answer?

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.