cloudinary_gem icon indicating copy to clipboard operation
cloudinary_gem copied to clipboard

Issues with `mount_uploaders`

Open diazruy opened this issue 6 years ago • 8 comments

I have a model in which I'm storing the image public IDs in an Array (a JSONB object, technically) in my Postgres DB record. I have made the images available via:

class MyModel < ApplicationRecord
  mount_uploaders :images, MyImageUploader
end

I'm not actually uploading any images via my app, I actually only need this in order to display images I have uploaded to Cloudinary elsewhere. The problem I'm running into with this use of mount_uploaders is that when I call:

image = MyModel.first.images.first
image.small.url 
# => NoMethodError: undefined method `my_public_id' for #<Array:0x00007fa4b43664c8>
# from /home/ruy/.rvm/gems/ruby-2.4.3/gems/cloudinary-1.9.1/lib/cloudinary/carrier_wave.rb:217:in `block (2 levels) in override_in_versions'

Same if I do image.versions(:small).url or image.url(:small).

It appears that the lookup of the my_public_id method is not going to the right place (Array vs MyImageUploader ). Am I doing something incorrectly or is this an actual issue? Note that this doesn't seem to happen if I call this on an asset mounted via mount_uploader.

diazruy avatar May 23 '18 22:05 diazruy

Hi @diazruy, Multiple uploads with mount_uploaders is currently not supported (in the works, but no ETA yet). In the meantime, as a workaround, you can do something like the following sample project: https://github.com/taragano/Cloudinary_multiple_uploads

roeeba avatar May 26 '18 17:05 roeeba

Can we get a printed warning when mount_uploaders is used with cloudinary (or, jankily, when Storage#store! is called on a pluralized #mounted_as) or anything of sorts?

Currently, the point in time where the usage of mount_uploaders causes you any bugs can be a long way into the future. If a warning can arrive before the multiple uploads support it would be really nice.

caioertai avatar May 28 '19 22:05 caioertai

Hi @caioertai. Thanks for the feedback! I'm forwarding this to the relevant team to review. We'll update here once we have any news.

roeeba avatar Jun 12 '19 20:06 roeeba

Hi @caioertai. Just updating that our team has added this enhancement to its roadmap, currently not in the near-future plans though. We'll update if and when we'll have any progress.

roeeba avatar Jun 22 '19 18:06 roeeba

Any updates on this?

legos avatar Dec 19 '21 22:12 legos

Hi @legos. This feature is not currently in our plans. Would you mind sharing more information about your use case and what are you trying to achieve? We may be able to offer an alternative approach.

roeeba avatar Dec 30 '21 10:12 roeeba

@roeeba I know the recommended approach is to create a model such as event_image.rb, mount an image uploader on that model then make a has_many :event_images association on my Event model.

The issue I have is that I may want to upload multiple images from my EventImagesController index page w/o necessarily associating an event to those images. Doesn't seem to be a graceful way to handle that use case.

legos avatar Jan 03 '22 18:01 legos

@legos I am trying to understand the benefit of this use-case, it is not MVC at that point. What I am getting at is there needs to exist some record of the images that you add to an event (this is what the model is for) otherwise you won't have any record of this and will not know how to access those assets.

d-mendoza avatar Jan 04 '22 19:01 d-mendoza

Fixed in #501

const-cloudinary avatar Apr 02 '24 13:04 const-cloudinary