0

I'm trying to add a caption below my cloudinary image. On the cloudinary website, I've added my caption under the "edit metadata" field, but I can't figure out how to retrieve it.

My controller:

require 'cloudinary'
results = Cloudinary::Api.resources(:type => :upload)
resources = results["resources"]
@ids = resources.map {|res| res["public_id"]}

My view:

<% @ids.each do |id| %>
  <%= cl_image_tag (id) %>
  **insert caption here**
<% end %>
Ben
  • 367
  • 1
  • 5
  • 19

1 Answers1

1

To get the image metadata you've inserted, you'll have to set context to true when running the resources method, like this:

results = Cloudinary::Api.resources(:type => :upload, :context => true)

The above request will also return key-value pairs as in the metadata you've inserted, like this:

"context"=>{"custom"=>{"caption"=>"flowers"}}

Roee Ben-Ari
  • 600
  • 3
  • 12
  • Any tips on how to efficiently extract the caption when not all photos in the list have captions? – Ben Aug 21 '17 at 13:09