为了保持 DRY,我有一个 ModelBase 类,其中包含 Mongoid 文档,如下所示:
class ModelBase
include Mongoid::Document
alias_attribute :guid, :id
def as_json(options = {})
azove_hash = options.merge(:methods => :guid)
super azove_hash
end
end
然后我所有的模型都从 ModelBase 继承,它们似乎工作正常。但是,有一种型号我使用 CarrierWave。当它从 ModelBase 继承时,对 mount_uploader 的调用失败。当我在没有子类的情况下包含模型时,它工作正常。难道不能在从另一个类继承的类中使用carrierwave吗?
这是失败的类的版本。将不胜感激任何建议/想法
require 'carrierwave/orm/mongoid'
class SomeOtherModel < ModelBase
field :abstract
validates :abstract, :presence => true
field :category
validates :category, :presence => true, :inclusion => {:in => %w{audio graphics text video}}
field :content_uri
validates :content_uri, :presence => true
has_and_belongs_to_many :topics
has_and_belongs_to_many :events
has_and_belongs_to_many :authors, :class_name => "User"
mount_uploader :content, ContentUploader
attr_accessible :abstract, :category, :content, :content_uri, :authors, :topics, :events
end