mongoid版本:mongoid(2.4.12) rails -v#=> Rails 3.1.10
class A
include Mongoid::Document
field :foo
def self.inherited(klass)
end
end
class B < A
field :bar
end
class C < A
end
#C.new
# => #<C _id: 514c9505e3e50a856b000001, _type: "C", foo: nil, bar: nil>
答案 0 :(得分:2)
您需要致电super
,否则您将覆盖任何先前定义的inherited
方法。所以你的功能应该是:
def self.inherited(klass)
super
#your code here
end