ruby 如何通过Cloudinary Active Storage向附加到模型的图像添加替代文本?

xpszyzbs  于 2023-08-04  发布在  Ruby
关注(0)|答案(1)|浏览(98)

我正在处理一个项目,该项目将_many_photos_附加到项目模型。我通过我的种子中的Cloudinary Active Storage将照片附加到Project的每个新示例中,如下所示:

file = URI.open("URL_TO_PHOTO")
project.photos.attach(io: file, filename: "PHOTO.png", content_type: "image/png")

字符串
当我想显示照片时,我会执行以下操作:

<% @project.photos.each do |photo| %>
    <%= cl_image_tag photo.key %>
<% end %>


我想确保我的网站是可访问的,所以我想添加'alt文本'到我所有的图像。然而,我不确定在哪里可以做到这一点-理想情况下,我会添加alt文本时,我附加的照片在种子。
我使用Ruby和Ruby on Rails。
有人有什么想法吗?
我试着在这里简单地添加它:

<% @project.photos.each do |photo| %>
   <%= cl_image_tag photo.key alt="alt text goes here" %>
<% end %>


但从rails收到以下错误:第一个月

mqxuamgl

mqxuamgl1#

请尝试以下操作:

cl_image_tag "sample.png", :width=>100, :height=>100, :alt=>"hello"

字符串
上面是Repo的例子:https://github.com/cloudinary/cloudinary_gem/blob/master/lib/cloudinary/helper.rb#L22

相关问题