I would like to duplicate a model. The original model contains an attachment through Carrierwave. Ideally, a new attachment would be created, that is a copy of the original image, for the new model object.
I have looked through the Carrierwave documentation, and googled this problem, but have not found a solution that creates a new duplicate of the original image. Is this reasonable? Possible?
While
copy_carrierwave_file
is a neat gem it is not nescessary as long as you use local storage.carrierwave
can use local files as source of attachments and you can use this to duplicate the attachment:This is more efficient than routing the image twice through your web server.
For me with CarrierWave 0.10 this works just fine:
Although I'm not sure how this works out when using cloud storage like S3
I don't believe Carrierwave has this option. However, you can make use of the *_remote_url= method to set the new model's picture to be a duplicate of the first.
Here's a brief example
Say I have a model which has_one :photo attached with carrierwave. I can duplicate, the model, set the photo to the previous one and save it. Example:
This would then "copy" the photo from the first object into your second as a new carrierwave attachment.
Try this gem https://github.com/equivalent/copy_carrierwave_file , it handles both local storage and Fog storage