简体   繁体   English

NameError:类的未定义方法“ options”

[英]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

Taken from here : 这里拍摄:

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.

相关问题 NameError:rails 4中类“状态”的未定义方法“ xyz” - NameError: undefined method `xyz' for class `State' in rails 4 章鱼宝石的Rails错误中类&#39;Class&#39;(NameError)的未定义方法&#39;announce&#39; - undefined method `announce' for class `Class' (NameError) in rails error in octopus gem 为Ruler :: Application:Class(NameError)产生机架未定义的局部变量或方法`env&#39; - rackup undefined local variable or method `env' for Rulers::Application:Class (NameError) NameError:HomeController:Class的未定义局部变量或方法“请求” - NameError: undefined local variable or method `request' for HomeController:Class 类Minitest :: Unit的未定义方法_run_suites(NameError) - undefined method `_run_suites' for class `Minitest::Unit' (NameError) NameError未定义的局部变量或方法 - NameError undefined local variable or method NameError:未定义的局部变量或方法 - NameError: undefined local variable or method “ method_missing”:未定义的局部变量或AppName :: Application:Class的方法“开发”(NameError) - `method_missing': undefined local variable or method `development' for AppName::Application:Class (NameError) NameError undefined local variable or method `primary_abstract_class' for #<class:xxxxx></class:xxxxx> - NameError undefined local variable or method `primary_abstract_class' for #<Class:xxxxx> NameError:未定义的局部变量或扫描方法上的方法 - NameError: undefined local variable or method on scan method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM