如何从 cloudinary 和 rails 检索图像说明?

How to retreive image captions from cloudinary and rails?

我正在尝试在我的云图像下方添加说明。在 cloudinary 网站上,我在 "edit metadata" 字段下添加了我的标题,但我不知道如何检索它。

我的控制器:

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

我的看法:

<% @ids.each do |id| %>
  <%= cl_image_tag (id) %>
  **insert caption here**
<% end %>

要获取您插入的图像元数据,您必须将 context 设置为 true 当 运行 使用 resources 方法时,如下所示:

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

上述请求还将 return 键值对,就像您插入的元数据中一样,如下所示:

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