我有一种方法可以在Carrierwave中复制图像,但在运行时会收到错误Validation failed: Image could not download file
。它创建一个Invoice副本,然后浏览它的相关图像,将它们设置为remote_image_url并重新上传它们。
我认为这与图片网址末尾的AccessKey信息有关。有什么想法吗?
def self.duplicate_it(invoice)
new_invoice = invoice.dup
new_invoice.save
if invoice.images.any?
invoice.images.each do |i|
temp_image = i.image
new_image = Image.new(:remote_image_url => temp_image.to_s, :order_id => new_invoice.id)
new_image.save!
end
end
end
答案 0 :(得分:0)
这有效
new_invoice = invoice.dup :include => {:lineitems => :images} do |original, kopy|
kopy.image = original.image if kopy.is_a?(Image)
end