[英]ruby attr_accessor missing method
New to RoR, I'm using the Carmen gem, running a rake gives me the error: RoR的新手,我使用的是Carmen gem,运行耙子给我错误:
Failed: NoMethodError: undefined method `excluded_states=' for Carmen:Module 失败:NoMethodError:Carmen:Module的未定义方法“ excluded_states =”
but the gem includes the attr_accessor method with :excluded_states in the args. 但是gem包含attr_accessor方法,并且在args中带有:excluded_states。
Doesn't the attr_accessor method automagically create the `excluded_states=' setter method? attr_accessor方法不是自动创建`excluded_states ='setter方法吗?
You can't call attr_accessor
within a module, that's something that should only work within a class. 您不能在模块内调用
attr_accessor
,那只能在一个类中使用。 What you want instead is the mattr_accessor
variant: 您想要的是
mattr_accessor
变体:
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. 也有可能定义正确,但是您引用错误,因为您应该在某事实例上调用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.