ruby copy a paperclip attachment from one model to another?
This should do the trick, you could use an after_create
callback if the models are associated, if not I would recommend doing it in the controller action that creates the card.
instance_of_model_one.cardimage = instance_of_model_two.avatar
instance_of_model_one.save
How to copy a file using Paperclip
After some more messing around with paperclip, I figured it out. It's ridiculously simple to copy files!
# Stupid example method that just copies a user's profile pic to another user.
def copy_profile_picture(user_1, user_2)
user_2.picture = user_1.picture
user_2.save # Copied the picture and we're done!
end
This also works great with amazon s3. Sweet
Rails - How to Move a PaperClip Model to Another Model
I've just tried the following:
Given two models, with a picture
attachment and their own Paperclip configurations, say: Gallery1 and Gallery2.
Given I had one object in Gallery1 with a picture already attached.
Make:
Gallery2.create(:picture => Gallery1.first.picture)
And it creates the picture properly resized with the constraints of Gallery2.
Related Topics
You Don't Have Write Permissions into the /Var/Lib/Gems/1.9.1 Directory
Regex to Validate String Having Only Characters (Not Special Characters), Blank Spaces and Numbers
Script to Run Against Stdin If No Arg; Otherwise Input File =Argv[0]
Creating a Test Suite Using Ruby Minitest
Rails Routes: Get Without Param :Id
In Ruby, How to Find Out If a String Is Not in an Array
Ruby -V Dyld: Library Not Loaded: /Usr/Local/Lib/Libgmp.10.Dylib
Is It a Good Idea to Purge Old Rails Migration Files
How to Programmatically Check If a Certificate Has Been Revoked
Installing Libyaml for Ruby on a MAC Osx (Lion)
Setting Mime Type for .Ogv Files in Rails Development Environment
How to Generate a Wsdl Using Ruby