# Cloning an already uploaded image using attachment\_fu

**URL:** <https://www.ruby-forum.com/t/cloning-an-already-uploaded-image-using-attachment-fu/160553>\
**Category:** Rails\
**Created:** [February 17, 2009, 5:41pm UTC](https://www.ruby-forum.com/t/cloning-an-already-uploaded-image-using-attachment-fu/160553 "2009-02-17T17:41:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![semyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ce7236/32.png) [@semyou](https://www.ruby-forum.com/u/semyou)\
**Post date:** [February 17, 2009, 5:41pm UTC](https://www.ruby-forum.com/t/cloning-an-already-uploaded-image-using-attachment-fu/160553/1 "2009-02-17T17:41:54Z")

</div>

Hi,

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

[http://danieloshea.com/articles/254-cloning-images](http://danieloshea.com/articles/254-cloning-images)

# 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
        n.save_to_storage
        c.thumbnails<<n
     end
   c.temp_path = self.create_temp_file
   c.save_to_storage
   c.save
   return c
  end

```

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?

Thanks,

---

<div class="post-metadata">

**Author:** ![semyou](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ce7236/32.png) [@semyou](https://www.ruby-forum.com/u/semyou)\
**Post date:** [February 17, 2009, 6:39pm UTC](https://www.ruby-forum.com/t/cloning-an-already-uploaded-image-using-attachment-fu/160553/2 "2009-02-17T18:39:46Z")

</div>

class Image \< ActiveRecord::Base

#you attachment fu config

def clone  
cloned = super  
cloned.filename = “#{rand(1000)}\_#{self.filename}”  
cloned.temp\_data = File.read( self.full\_filename )  
cloned  
end

end

#code

cloned\_image = some\_image.clone  
cloned\_image.save! #saving the image will also create the thumbnails

- 

Maurício Linhares  
[http://alinhavado.wordpress.com/](http://alinhavado.wordpress.com/) (pt-br) | [http://blog.codevader.com/](http://blog.codevader.com/)  
(en)

On Tue, Feb 17, 2009 at 1:41 PM, Youssef S.
