Rails3 では、Item と Upload の 2 つのモデルを定義しました。アイテムには、ポリモーフィックな関連付けを持つ多数のアップロードがあります。
定義は次のようになります。
class Item
include MongoMapper::Document
include MongoMapper::AcceptsNestedAttributes
attr_accessible :uploads_attributes
belongs_to :category
many :uploads,:as => :picture_of
accepts_nested_attributes_for :uploads
key :name, String
key :description, String
validates_presence_of :name
timestamps!
end
class Upload
require 'carrierwave/orm/mongomapper'
include MongoMapper::EmbeddedDocument
attr_accessible :image,:remote_image_url
# belongs to Item, Event
# upload , just for photo
belongs_to :picture_of, :polymorphic => true
key :versions, Array
mount_uploader :image, ImageUploader
timestamps!
# for nested_attributes
def _destroy
end
end
アップロード属性を使用してアイテムを作成しようとすると、検証が失敗するため失敗します。私の定義に問題はありますか?