jeudi 6 juillet 2023

How to add alt-text to images attached to model via Cloudinary Active Storage?

I'm working on a project that has_many_photos_attached to a Project model. I'm attaching photos to each new instance of Project via Cloudinary Active Storage in my Seeds like so: file = URI.open("URL_TO_PHOTO") project.photos.attach(io: file, filename: "PHOTO.png", content_type: "image/png")

When I want to display the photo(s), I do the following: <% @project.photos.each do |photo| %> <%= cl_image_tag photo.key %> <% end %>

I want to be sure that my site is accessible, so I want to add 'alt-text' to all my images. However, I'm not sure where this can be done - ideally I would add the alt text when I attach the photo in the seeds.

I'm using Ruby and Ruby on Rails.

Anyone have any ideas?

I've tried adding it simply here:

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

but received the following error from rails: "wrong number of arguments (given 1, expected 0)"

Aucun commentaire:

Enregistrer un commentaire