Simple gem for copying CarrierWave files between resources. It's solving issues with local and remote storage discussed here
Add this line to your application's Gemfile:
gem 'copy_carrierwave_file'
And then execute:
$ bundle
You can use service class directly:
original_resource = User.last
new_resource = User.new
CopyCarrierwaveFile::CopyFileService.new(original_resource, new_resource, :avatar).set_file
# :avatar represents mount point (field)
new_resource.save
or you can include CopyCarrierwaveFile
module and call copy_carrierwave_file
:
class Document
include CopyCarrierwaveFile
mount_uplader :content_file, MyUploader
def duplicate_file(original)
copy_carrierwave_file(original, self, :content_file)
self.save!
end
end
document = Document.new
document.duplicate_file(Document.last)
Functionality is the same
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request