我正在处理一个项目,该项目将_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收到以下错误:第一个月
1条答案
按热度按时间mqxuamgl1#
请尝试以下操作:
字符串
上面是Repo的例子:https://github.com/cloudinary/cloudinary_gem/blob/master/lib/cloudinary/helper.rb#L22