Undefined bson_type method for model in Rails and MongoId
I am having problems with mongoid when adding items to the embeds_many relation: undefined method bson_type for #<Discount:0x007f3c599747e8>
thanks in advance.
here is my code:
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
I tried with a different approach but with no success; (works for embdes_many, but not for a normal array).
class UsersController < ApplicationController
def review
...
current_user.discounts.push like_discount
current_user.client_ids.push params[:client_id]
...
end
end
+3
source to share
No one has answered this question yet
Check out similar questions: