Rails 5.2 deprecated the Action View helper image_alt(src).
The method takes the
src argument, which can be an image file path. It removes the basename and the digest of the image file path, and returns a titleized string after replacing hyphens and underscores with spaces.
Let’s see an example:
Usage in image_tag
image_alt was used to autogenerate
alt text from the
src attribute of an
Adding the following in a view:
Problems with default alt text
In the example above, the
alt text “Brand logo” will be read by screen readers.
More often than not, this automatically inferred text is not a useful description and adds unnecessary content.
Setting a meaningless
alt text messes with the screen reader’s default behavior for blank
That may be frustrating for assistive technology users.
This also results in linting tools giving false negatives.
It also makes improving application accessibility a tough job.
Rails 5.2 onwards
After deprecation, we had to explicitly set the
alt text while using an
And also had the option to just not provide an
image tag would have no
alt text in that case.
In Rails 6.0, this method has been removed. This was done as a part of removing all code which was deprecated in Rails 5.2.