0
在Rails3中,我定義了2個模型,只是Item和Upload。 項目有許多帶有多態關聯的上傳。Mongomapper父模型驗證失敗,accept_nested_attributes_for
定義看起來象下面這樣:
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
當試圖與上傳屬性來創建項目,它失敗,因爲驗證失敗。 我的定義有問題嗎?