image_alt

image_alt(src)
Instance Public methods

Returns a string suitable for an html image tag alt attribute. The src argument is meant to be an image file path. The method removes the basename of the file path and the digest, if any. It also removes hyphens and underscores from file names and replaces them with spaces, returning a space-separated, titleized string.

Examples

1
2
3
4
5
6
7
8
image_alt('rails.png')
# => Rails
 
image_alt('hyphenated-file-name.png')
# => Hyphenated file name
 
image_alt('underscored_file_name.png')
# => Underscored file name
doc_ruby_on_rails
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.