我在向embeds_many关系添加元素时遇到mongoid问题:undefined method bson_type for #<Discount:0x007f3c599747e8>
提前感谢。
这是我的代码:
class Discount
include Mongoid::Document
embedded_in :discountable, polymorphic: true
end
class User
include Mongoid::Document
embeds_many :discounts, as: :discountable
field :client_ids, type: Array
end
class UsersController < ApplicationController
def review
...
current_user.push discounts: like_discount
current_user.push client_ids: params[:client_id]
...
end
end
我尝试了另一种方法,但没有成功; (适用于embeds_many但不适用于普通数组)。
class UsersController < ApplicationController
def review
...
current_user.discounts.push like_discount
current_user.client_ids.push params[:client_id]
...
end
end