Programmable Media

Ruby/Rails quick start

Last updated: Dec-04-2023

This quick start is intended to let you quickly try using several common Cloudinary features. It doesn't necessarily employ coding best practices and the code you create here isn't intended for production.

You can perform this quick start in a code sandbox or in a clean project in the dev environment of your choice.

You can also view the completed code of this quick start in a GitHub repo.

This quick start can be performed using any Ruby framework or environment.

Tip
If you aren't familiar with Cloudinary, you may want to first take a look at the Developer get started guide for a high-level overview of integrating Cloudinary into your code, and an introduction to the main concepts.

You may also find our Glossary helpful to understand Cloudinary-specific terminology.

Prerequisites

To perform this quick start, you'll need:

1. Set up and configure the SDK

Install the SDK

In a terminal, in your Ruby environment, run:

Configure Cloudinary

In your project, create a new file called config.rb with the code below. Make sure to update it to use your product environment's credentials.

config.rb

Important
When writing your own applications, follow your organization's policy on storing secrets and don't expose your API secret.

Reference the configuration from a ruby script

In your project, create a new file called quickstart.rb.

For the sake of this quick start, you'll put all the Cloudinary code other than the configuration in this single file and only run it at the end.

To reference your product environment configuration from this new file, add:

quickstart.rb

2. Upload files

To upload some remote files to Cloudinary, paste the following to the end of your quickstart.rb file:

quickstart.rb (continued)

3. Get and use details of an image

Paste these two snippets to perform some management operations on the assets you previously uploaded:

Return details of an existing resource

quickstart.rb (continued)

Retrieve and update specific attributes of an asset

quickstart.rb (continued)

4. Transform images

Add this code to your file in order to generate a few different transformation URLs on the two assets you previously uploaded:

quickstart.rb (continued)

5. Run your code

In your Ruby IDE or in a terminal (from the /scripts folder of your project), run your quickstart.rb script and take a look at the output you get from each step of this quick start:

View the completed code

You can find the full code example for this quick start on GitHub.

Next steps

  • Learn more about the Ruby/Rails SDK by visiting the other pages in this SDK guide.
  • Get comprehensive details about Cloudinary features and capabilities:
Cloudinary Academy

 

Check out our Introduction to Cloudinary for Ruby Developers course in the Cloudinary Academy. This self-paced resource provides video-based lessons, sample scripts and other learning material to get you going with Ruby and Cloudinary today.

✔️ Feedback sent!

Rate this page: