简体   繁体   中英

How to retreive image captions from cloudinary and rails?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM