attachinary icon indicating copy to clipboard operation
attachinary copied to clipboard

Adding images to existing array?

Open skwp opened this issue 12 years ago • 3 comments

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']

skwp avatar Mar 07 '13 20:03 skwp

This appears to re-upload to cloudinary!

skwp avatar Mar 07 '13 20:03 skwp

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.

skwp avatar Mar 13 '13 20:03 skwp

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.

assembler avatar Mar 26 '13 16:03 assembler