Cloudinary GEM for Ruby on Rails integration
Switch branches/tags
Nothing to show
Pull request Compare This branch is 3 commits ahead, 484 commits behind cloudinary:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Cloudinary is a cloud service that offers a solution to a web application's entire image management pipeline.

Easily upload images to the cloud. Automatically perform smart image resizing, cropping and conversion without installing any complex software. Integrate Facebook or Twitter profile image extraction in a snap, in any dimension and style to match your website’s graphics requirements. Images are seamlessly delivered through a fast CDN, and much much more.

Cloudinary offers comprehensive APIs and administration capabilities and is easy to integrate with any web application, existing or new.

Cloudinary provides URL and HTTP based APIs that can be easily integrated with any Web development framework.

For Ruby on Rails, Cloudinary provides a GEM for simplifying the integration even further.


To install the Cloudinary Ruby GEM, run:

$ gem install cloudinary

If you use Rails 3.x or higher, edit your Gemfile, add the following line and run bundle install

$ gem 'cloudinary'

Or in Rails 2.x, edit your environment.rb and add:

$ config.gem 'cloudinary'

If you would like to use our optional integration module of image uploads with ActiveRecord using CarrierWave, install CarrierWave GEM:

Rails 3.x: edit your Gemfile and run bundle install:

$ gem 'carrierwave'
$ gem 'cloudinary'

Rails 2.x environment.rb:

$ config.gem 'carrierwave', :version => '~> 0.4.1'
$ config.gem 'cloudinary'

Note: The CarrierWave GEM should be loaded before the Cloudinary GEM.

Try it right away

Sign up for a free account so you can try out image transformations and seamless image delivery through CDN.

Note: Replace demo in all the following examples with your Cloudinary's cloud name.

Accessing an uploaded image with the sample public ID through a CDN:


Generating a 150x100 version of the sample image and downloading it through a CDN:,h_100,c_fill/sample.jpg

Sample 150x100

Converting to a 150x100 PNG with rounded corners of 20 pixels:,h_100,c_fill,r_20/sample.png

Sample 150x150 Rounded PNG

For plenty more transformation options, see our image transformations documentation.

Generating a 120x90 thumbnail based on automatic face detection of the Facebook profile picture of Bill Clinton:,g_face,h_90,w_120/billclinton.jpg

Facebook 90x120

For more details, see our documentation for embedding Facebook and Twitter profile pictures.



Each request for building a URL of a remote cloud resource must have the cloud_name parameter set. Each request to our secure APIs (e.g., image uploads, eager sprite generation) must have the api_key and api_secret parameters set. See API, URLs and access identifiers for more details.

Setting the cloud_name, api_key and api_secret parameters can be done either directly in each call to a Cloudinary method or by globally setting using a YAML configuration file.

Cloudinary looks for an optional file named cloudinary.yml, which should be located under the config directory of your Rails project. It contains settings for each of your deployment environments. You can always override the values specified in cloudinary.yml by passing different values in specific Cloudinary calls.

You can download your customized cloudinary.yml configuration file using our Management Console.

Embedding and transforming images

Any image uploaded to Cloudinary can be transformed and embedded using powerful view helper methods:

The following example generates an image of an uploaded sample image while transforming it to fill a 100x150 rectangle:

cl_image_tag("sample.jpg", :width => 100, :height => 150, :crop => :fill)

Another example, emedding a smaller version of an uploaded image while generating a 90x90 face detection based thumbnail:

cl_image_tag("woman.jpg", :width => 90, :height => 90, 
             :crop => :thumb, :gravity => :face)

You can provide either a Facebook name or a numeric ID of a Facebook profile or a fan page.

Embedding a Facebook profile to match your graphic design is very simple:

facebook_profile_image_tag("billclinton.jpg", :width => 90, :height => 130, 
                           :crop => :fill, :gravity => :north_west)

Same goes for Twitter:


See our documentation for more information about displaying and transforming images in Rails.


Assuming you have your Cloudinary configuration parameters defined (cloud_name, api_key, api_secret), uploading to Cloudinary is very simple.

The following example uploads a local JPG to the cloud:


The uploaded image is assigned a randomly generated public ID. The image is immediately available for download through a CDN:


You can also specify your own public ID:

Cloudinary::Uploader.upload("", :public_id => 'sample_remote')


See our documentation for plenty more options of direct uploading to the cloud from your Ruby code.

CarrierWave Integration

Cloudinary's Ruby GEM includes an optional plugin for CarrierWave. If you already use CarrierWave, simply include Cloudinary::CarrierWave to switch to cloud storage and image processing in the cloud.

class PictureUploader < CarrierWave::Uploader::Base    
    include Cloudinary::CarrierWave        

For more details on CarrierWave integration see our documentation.

We also published an interesting blog post about Ruby on Rails image uploads with CarrierWave and Cloudinary.

Additional resources

Additional resources are available at:


You can open an issue through GitHub.

Contact us at

Or via Twitter: @cloudinary


Released under the MIT license.