Skip to content

Commit 76c35b1

Browse files
committed
Improve alt and title attributes in image helper methods to use entity name or string representation
1 parent 5bfd3ee commit 76c35b1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

app/helpers/better_together/image_helper.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ def cover_image_tag(entity, options = {}) # rubocop:todo Metrics/MethodLength, M
1212
image_width = options[:width] || 2400
1313
image_height = options[:height] || 600
1414
image_format = options[:format] || 'jpg'
15-
image_alt = options[:alt] || entity
16-
image_title = options[:title] || entity
15+
image_alt = options[:alt] || entity&.to_s || entity&.name || 'Cover image'
16+
image_title = options[:title] || entity&.to_s || entity&.name || 'Cover image'
1717
image_tag_attributes = {
1818
class: image_classes,
1919
style: image_style,
@@ -52,8 +52,8 @@ def card_image_tag(entity, options = {}) # rubocop:todo Metrics/MethodLength, Me
5252
image_width = options[:width] || 1200
5353
image_height = options[:height] || 800
5454
image_format = options[:format] || 'jpg'
55-
image_alt = options[:alt] || entity
56-
image_title = options[:title] || entity
55+
image_alt = options[:alt] || entity&.to_s || entity&.name || 'Card image'
56+
image_title = options[:title] || entity&.to_s || entity&.name || 'Card image'
5757
image_tag_attributes = {
5858
class: image_classes,
5959
style: image_style,

0 commit comments

Comments
 (0)