Rails和MongoId中模型的未定义方法bson_type

时间:2015-05-14 03:17:05

标签: ruby-on-rails ruby ruby-on-rails-4 mongoid

我在向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

0 个答案:

没有答案