我有一个设计模型在两个关联(full_image和preview)中有两个Paperclip附件。我希望只有在full_image和preview都具有有效文件但似乎无法使其工作的情况下才能保存设计。现在,这是我期望的工作,但它并不仅仅在我提交表单时不会验证附件。如何验证嵌套模型中的附件?
class Design < ActiveRecord::Base
has_one :full_image, :as => :assetable, :class_name => "FullImage", :dependent => :destroy
has_one :preview , :as => :assetable, :class_name => "Preview" , :dependent => :destroy
accepts_nested_attributes_for :full_image, :preview
validates_associated :preview, :full_image
end
class Asset < ActiveRecord::Base
belongs_to :assetable, :polymorphic => true
delegate :url, :to => :attachment
end
class FullImage < Asset
has_attached_file :attachment
validates_attachment_presence :attachment
end
class Preview < Asset
has_attached_file :attachment
validates_attachment_presence :attachment
end
有人可以请建议我应该做什么?