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
ruby ruby-on-rails ruby-on-rails-4 mongoid


source to share


No one has answered this question yet

Check out similar questions:

1339
How can I rename a database column in Ruby on Rails migrations?
1023
How do I get the current absolute url in Ruby on Rails?
941
Understanding Rails Authentication ID
876
Brief explanation of nil v. Empty v. Blank in Ruby on Rails
596
How to use problems in Rails 4
five
delete inline document in mongoid
3
MongoDB Schema Design --- Friendship with Groups
1
Update inline document field on multiple Mongoid documents
0
Can't modify data with Mongoid
0
uninitialized constant Mongoid :: Spacial :: Document :: ClassMethods :: Mongo



All Articles
Loading...
X
Show
Funny
Dev
Pics