我正在尝试创建一个包含与 Mongoid 的多态关系的模块。简化示例:
module Scalable
extend ActiveSupport::Concern
included do
references_many :scales, :as => :scalable
before_save :add_scale
end
module InstanceMethods
def add_scale
self.scales.create
end
end
end
class Scale
include Mongoid::Document
referenced_in :scalable, :index => true
end
class ScalableModel
include Mongoid::Document
include Scalable
end
但是,当我尝试运行类似的东西时ScalableModel.create
,我收到以下错误:
NoMethodError Exception: undefined method `relations' for Scalable:Module
这是不可能的,还是我做错了什么?