我有一個設計模型在兩個關聯(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
有人可以請建議我應該做什麼?