我有如下的 Mongoid 类:
class Order
include Mongoid::Document
embeds_many :animals
end
class Animal
include Mongoid::Document
embedded_in :order
def self.has_gender
field :gender, type: String
end
end
class Deer < Animal
has_gender
end
当我按任何订单召唤动物时,即使是空的:
Order.new.animals
我收到以下错误:
undefined method `has_gender' for Deer:Class
有任何想法吗?