cloudinary_gem
cloudinary_gem copied to clipboard
Issues with `mount_uploaders`
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
.
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
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.
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.
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.
Any updates on this?
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 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 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.
Fixed in #501