【发布时间】:2013-07-04 14:45:29
【问题描述】:
在 Rails3 中,我定义了 2 个模型,只有 Item 和 Upload。 项目有许多具有多态关联的上传。
定义如下:
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
当尝试使用 Uploads 属性创建项目时,它会失败,因为验证失败。 我的定义有问题吗?
【问题讨论】:
标签: ruby-on-rails ruby mongomapper