Youssef Semlani
2009-Feb-17 16:41 UTC
cloning an already uploaded image using attachment_fu
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
# 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,
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
MaurĂcio Linhares
2009-Feb-17 17:39 UTC
Re: cloning an already uploaded image using attachment_fu
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/ (pt-br) | http://blog.codevader.com/ (en)
On Tue, Feb 17, 2009 at 1:41 PM, Youssef Semlani
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
> 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
>
>
> # 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,
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---