在载波中复制图像

时间:2012-11-16 02:55:07

标签: ruby-on-rails-3 amazon-s3 carrierwave

我有一种方法可以在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

1 个答案:

答案 0 :(得分:0)

这有效

new_invoice = invoice.dup :include => {:lineitems => :images} do |original, kopy|
  kopy.image = original.image if kopy.is_a?(Image)
end