attachinary
attachinary copied to clipboard
Adding images to existing array?
There seems to be no easy way to attach a new image to an array. If I have
has_attachments :photos
Then
model.photo_urls = [...] works
But what if I want to add an image to this array? I would have to get the urls to all the existing images first?
model.photo_urls = model.photos.map(&:fullpath) + ['new image path']
This appears to re-upload to cloudinary!
Fyi, this is the ugliness I had to resort to in order to implement file adding functionality:
result = Attachinary::Utils.process_hash(Cloudinary::Uploader.upload(url,
:transformation => {...},
:eager => {...}
))
result.scope = 'photos'
result.position = position || item.photo_files.count
item.photo_files << result
If there's a better way I'd love to know.
Method name there is unfortunate. What it does is it uploads given list of urls. If you want to upload another image, just pass the new one.