[英]NameError: undefined method 'options' for class
When I create instance of class, Error is raised NameError: undefined method 'options' for class 'Product'. 当我创建类的实例时,会引发错误NameError:类“ Product”的未定义方法“ options”。
DB: MongoDB 3.6 DB:MongoDB 3.6
Class Product
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Attributes::Dynamic
field :options, type: Hash, default: {}
end
gem: mongoid (6.1.1) 宝石:蒙古包(6.1.1)
NOTE: It works well when I change field name to option
or anything else, only options Fails. 注意:当我将字段名称更改为
option
或其他任何内容时,它工作得很好,仅选项失败。 TIA TIA
Reserved names
保留名称
If you define a field on your document that conflicts with a reserved method name in Mongoid, the configuration will raise an error.
如果您在文档上定义的字段与Mongoid中的保留方法名称冲突,则配置将引发错误。 For a list of these you may look at Mongoid.destructive_fields.
有关这些列表的信息,请参见Mongoid.destructive_fields。
Some code from mongoid: 来自mongoid的一些代码:
# File 'lib/mongoid/config.rb', line 69
def destructive_fields
Composable.prohibited_methods
end
# File 'lib/mongoid/composable.rb', line 98
def prohibited_methods
@prohibited_methods ||= MODULES.flat_map do |mod|
mod.instance_methods.map(&:to_sym)
end
end
MODULES
constant contains Fields
module at least which defines options
method. MODULES
常数至少包含Fields
模块,该模块定义了options
方法。 Maybe it's the reason. 也许是原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.