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 %>
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"}}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.