我不确定我在这里做错了什么。文件上传正常,但如果我提交表单而不选择要上传的文件,则会删除以前附加的图像。
ActiveAdmin 表单如下所示:
form do |f|
f.inputs do
f.input :model_number
f.input :description
f.input :slug
f.input :categories
f.has_many :product_images do |image|
image.input :product_id, as: :hidden, id: :product_id, input_html: { value: "%i" }
image.input :image
end
end
f.actions
end
以及各个型号的相关部分:
class ProductImage < ActiveRecord::Base
belongs_to :product
mount_uploader :image, ProductImageUploader
validates :image, :product_id, presence: true
end
class Product < ActiveRecord::Base
has_many :product_images, dependent: :destroy
accepts_nested_attributes_for :product_images
validates_associated :product_images
end
任何见解将不胜感激。谢谢!