簡體   English   中英

NameError:類的未定義方法“ options”

[英]NameError: undefined method 'options' for class

當我創建類的實例時,會引發錯誤NameError:類“ Product”的未定義方法“ options”。

DB:MongoDB 3.6

Class Product
     include Mongoid::Document
     include Mongoid::Timestamps
     include Mongoid::Attributes::Dynamic

     field :options, type: Hash, default: {}
end

寶石:蒙古包(6.1.1)

注意:當我將字段名稱更改為option或其他任何內容時,它工作得很好,僅選項失敗。 TIA

這里拍攝:

保留名稱

如果您在文檔上定義的字段與Mongoid中的保留方法名稱沖突,則配置將引發錯誤。 有關這些列表的信息,請參見Mongoid.destructive_fields。

來自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常數至少包含Fields模塊,該模塊定義了options方法。 也許是原因。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM