Sravan Kumar
Sravan Kumar

Reputation: 693

How to access two same classes in ruby on rails

I have class called Configuration that is called in my controller. Instead of instantiating my Configuration class, it is trying to instantiate a ActiveSupport::Configurable::Configuration.

How can I access my Configuration class, named the same as another library's Configuration?

class SampleController < ActionController::Base
  def m1
    cfg = Configuration.new
  end
end

Upvotes: 0

Views: 45

Answers (1)

Dave Newton
Dave Newton

Reputation: 160191

class SampleController < ActionController::Base
  def m1
    cfg = ::Configuration.new
  end
end

I'd recommend putting your own classes in their own modules, though.

In addition to avoiding class name collisions like this, it provides a structure from which you can hang more of your own code.

Upvotes: 1

Related Questions