rizidoro rizidoro - 1 year ago 50
Ruby Question

Rails "is not a module" error

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


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

So, in my result_controller I'm doing this:

require 'insurance/broker/fake_broker'

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

but Rails is returning this error:

Insurance is not a module

What's wrong here?

Answer Source

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)