cloudinary_gem
cloudinary_gem copied to clipboard
Incorrect documentation for ActiveStorage integration (Rails 6.1.4)
Hi,
First, thank you for this gem.
I've been using Cloudinary along with ActiveStorage on a project, and I figured the documentation is incorrect when it comes to generate Cloudinary URLs for ActiveStorage attachments using the cl_image_tag
and cloudinary_url
helpers.
Context
- Ruby 2.7
- Rails 6.1.4
- Cloudinary : 1.21.0 (latest stable version as of this issue's creation date)
The problem
The current documentation explains you just need to pass the ActiveStorage::Attached
instance as the first argument to the helper :
<%= cloudinary_url(@user.avatar, width: 300, height: 200, crop: :scale, effect: "cartoonify") %>
From my understanding, this calls cloudinary_url_internal
which, when using ActiveStorage, is overriden here:
def cloudinary_url_internal(source, options = {})
source = ActiveStorage::Blob.service.public_id(source) if defined? ActiveStorage::Blob.service.public_id
cloudinary_url_internal_original(source, options)
end
public_id
is defined here and seems to expect a key rather than the ActiveStorage source.
Because of this, cloudinary_url
returns an invalid URL that looks like this:
https://res.cloudinary.com/xxx/image/upload/c_scale,e_cartoonify,h_200,w_300/%23%3CActiveStorage::Attached::One:0x00007ff74ec1b3d8%3E
Workaround
Turns out you can work around the problem by passing the ActiveStorage source's key instead :
<%= cloudinary_url(@user.avatar.key, width: 300, height: 200, crop: :scale, effect: "cartoonify") %>
Question
Is the documentation actually incorrect and should the key be passed as described above in the workaround, or should the code be modified to actually expect an ActiveStorage source ?
Thanks!
@EmCousin Thank you for reporting this, you are correct. I will have our docs team update it.
The documentation has been updated. Closing this issue. Thanks!