I have a need to occasionally populate the image(s) stored on one
model's uploader from another. E.g.,
class Artwork
mount_uploader :image, ArtworkUploader
end
class Artist
mount_uploader :image, ArtistUploader
# copy an artwork image into the artist and perform necessary
processing
def replace_image_from(artwork)
artwork.image.cache_stored_file! unless artwork.image.cached?
self.image_cache = artwork.image_cache
self.store_image!
end
end
This almost worked, but our uploaders increment a version number that
goes into the store_path, and it turns out that calling
artwork.image.cache_stored_file! increments the version number on the
artwork, which actually hasn't changed. Is there a simpler way to read
the original file from one mount point into another?
Thanks,
Joey
original_resource = Artist.last
new_resource = Artwork.new
CopyCarrierwaveFile::CopyFileService.new(original_resource, new_resource, :image).set_file
# :avatar represents mount point (field)
new_resource.save