我有一个从PaymentMethod继承的PaymentPayPal类
class PaymentMethod
include Mongoid::Document
embedded_in :store
field :method, type: String
end
class PaymentKhipu < PaymentMethod
field :receiver_id, type: String
field :secret, type: String
end
但每次我想为商店建立付款方式我都会得到相同的父类
class Store
include Mongoid::Document
embeds_one :payment_method
end
s.build_payment_method({}, PaymentPayPal)
=> #<PaymentMethod _id: 529db89f24f1e727db000001, method: nil, _type: "PaymentMethod">
我可以手动创建类,但我想通过关联
创建它PaymentPayPal.new
=> #<PaymentPayPal _id: 529dba3324f1e727db000002, method: "paypal", _type: "PaymentPayPal", receiver_id: nil, secret: nil>
我正在使用mongoid 4.0和rails 4.0