Forum: Ruby on Rails cloning an already uploaded image using attachment_fu

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Youyou S. (Guest)
on 2009-02-17 18:41

I have an Image model that is attached to a item. The image was uploaded
through attachment_fu. Now, I want to reuse the same image for a new
item. I tried several tips found online. For example in

# Create a clone of an image and it's thumbnails.
      def create_clone
        c = self.clone
        self.thumbnails.each do |thumb|
            n = thumb.clone
            n.temp_path = thumb.create_temp_file
       c.temp_path = self.create_temp_file
       return c

But the end result is an exception at

 n.temp_path = thumb.create_temp_file

saying that undefined method temp_path (probably for the thumbnail n)???

I spent my whole weekend on it and I am pulling my hair off to solve it!

Any help?

Maurício L. (Guest)
on 2009-02-17 19:39
(Received via mailing list)
class Image < ActiveRecord::Base

  #you attachment fu config

  def clone
    cloned = super
    cloned.filename = "#{rand(1000)}_#{self.filename}"
    cloned.temp_data = self.full_filename )



cloned_image = some_image.clone! #saving the image will also create the thumbnails

Maurício Linhares (pt-br) |

On Tue, Feb 17, 2009 at 1:41 PM, Youssef S.
This topic is locked and can not be replied to.