Implementing Cloudinary uploads on Rails 6

Painless integration of the 'cloudinary' gem

Posted by Nelson on December 30, 2020
While it most definitely took a while for me to figure out how to completely integrate Cloudinary with this blog in the end it turns out it wasn't that hard at all, other than all the googling around, of course.

The first step is to add the Cloudinary gem to our gemfile:

bundle add cloudinary

and also 

bundle add image_processing

The image_processing gem did the trick to actually display the images uploaded via Trix (action_text). 

Provides higher-level image processing helpers that are commonly needed when handling image uploads.

Back at the Cloudinary control panel you can download an auto-generated cloudinary.yml (once logged into the Cloudinary panel: https://cloudinary.com/console/lui/cloudinary.yml), put this file inside the config folder. The file looks like this:

---
development:
  cloud_name: cloud_name
  api_key: 'key'
  api_secret: secret_key
  enhance_image_tag: true
  static_file_support: false
production:
  cloud_name: cloud_name
  api_key: 'key'
  api_secret: secret_key
  enhance_image_tag: true
  static_file_support: true
test:
  cloud_name: cloud_name
  api_key: 'key'
  api_secret: secret_key
  enhance_image_tag: true
  static_file_support: false

Now you need to edit the config/storage.yml file and add Cloudinary:

cloudinary:
  service: Cloudinary

Finally, add the below line to your desired environments inside config/environments/ (development, production, test, etc).

config.active_storage.service = :cloudinary

TBC