cloudinary / cloudinary_gem

Cloudinary GEM for Ruby on Rails integration
https://cloudinary.com
420 stars 285 forks source link

`cl_image_tag` and `cloudinary_url` ignores model class `ActiveStorage` service configuration #558

Closed enrique-fernandez-polo closed 1 week ago

enrique-fernandez-polo commented 3 weeks ago

Describe the bug in a sentence or two.

I have different ActiveStorage configuration with different folders to organize a little bit my images. The problem is that the SDK it's only getting the service from the global application configuration and not from the model class when present.

Issue Type (Can be multiple)

Steps to reproduce

local:
  service: Disk
  root: <%= Rails.root.join("storage") %>

cloudinary_brands:
  service: Cloudinary
  cloud_name: <%= ENV.fetch("CLOUDINARY_CLOUD_NAME") %>
  api_key: <%= ENV.fetch("CLOUDINARY_API_KEY") %>
  api_secret: <%= ENV.fetch("CLOUDINARY_API_SECRET") %>
  folder: <%= Rails.env + '/brands' %>
  secure: true
class Brand < ApplicationRecord
  has_one_attached :logo, service: :cloudinary_brands
end
config.active_storage.service = :local # If I set this to  :cloudinary_brands the URLs are properly generated

Error screenshots or Stack Trace (if applicable)

Operating System

Environment and Libraries (fill in the version numbers)

Repository

If possible, please provide a link to a reproducible repository that showcases the problem

tommyg-cld commented 3 weeks ago

@enrique-fernandez-polo so per your comment you need to set config.active_storage.service to :cloudinary_brands and this way the SDK will generate the proper Cloudinary URLs.

This is also mentioned in Active Storage configuration

Let me know if this answers your question.

enrique-fernandez-polo commented 3 weeks ago

Hello there!

I have six different configurations, I can not set the value there. I want everything to be uploaded by default using a service called local and use other more specific services for some cases.

For example I have cloudinary_brands and cloudinary_pictures each with different configurations.

PixelCook commented 2 weeks ago

@enrique-fernandez-polo This isn't currently supported, but I've opened a feature request. I don't have an approximate expected time that this would completed but we'll be sure to update you just as soon as it has.

In the meantime we will look into a workaround.