Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails "is not a module" error

I built a library on "lib" rails directory. The structure of library is something like this:

 lib/insurance/broker/fake_broker.rb

the class looks like the following example:

module Insurance
  module Broker
    class FakeBroker
      def initialize(user_id, user_secret)
        @user_id = user_id
        @user_secret = user_secret
      end
    end
  end
end

So, in my result_controller I'm doing this:

require 'insurance/broker/fake_broker'

 def show
   broker = Insurance::Broker::FakeBroker.new(1234,1234)
 end

but Rails is returning this error:

Insurance is not a module

What's wrong here?

like image 628
rizidoro Avatar asked Oct 01 '12 20:10

rizidoro


1 Answers

Ruby is telling you that it found an Insurance, but it is not a module. Perhaps you already have defined an Insurance class?

Depending on the surrounding code it might help if you "reset" the namespace by prepending a double colon:

broker = ::Insurance::Broker::FakeBroker.new(1234,1234)
like image 152
Daniel Rikowski Avatar answered Oct 19 '22 06:10

Daniel Rikowski