ruby attr_accessor missing method

270 Views Asked by At

New to RoR, I'm using the Carmen gem, running a rake gives me the error:

Failed: NoMethodError: undefined method `excluded_states=' for Carmen:Module

but the gem includes the attr_accessor method with :excluded_states in the args.

Doesn't the attr_accessor method automagically create the `excluded_states=' setter method?

1

There are 1 best solutions below

0
tadman On

You can't call attr_accessor within a module, that's something that should only work within a class. What you want instead is the mattr_accessor variant:

module MyModule
  mattr_accessor :excluded_states
end

It's also possible it is defined correctly but you're referencing it incorrectly, as in you should be calling that on an instance of something.