This blog is part of our Rails 7 series.
Rails 7.1 allows audio_tag and video_tag ActionView helpers to receive
Active Storage Attachments which implicitly unpacks the asset path to be
included in the src attribute of the <audio></audio> and <video></video>
tags.
Previously, the helper methods received only the asset path/url. To get the
asset path of an Active Storage Attachment, we had to explicitly call
polymorphic_path on the attachment, which returned the desired asset path.
audio_tag(polymorphic_path(user.audio_file))
# => <audio src="/..."></audio>
video_tag(polymorphic_path(user.video_file))
# => <video src="/..."></video>
audio_tag(user.audio_file)
# => <audio src="/..."></audio>
video_tag(user.video_file)
# => <video src="/..."></video>
Please check out this pull request for more details.

Written byGhouse Mohamed
Related blogs
- 01Rails 7.1 allows subscribing to transaction eventsJanuary 16, 2024 · Vishnu M
- 02Rails 7.1 adds path_params option to url_forNovember 7, 2023 · Neenu Chacko
- 03Rails 7.1 optimizes the default SQLite3 configurationOctober 31, 2023 · Vishnu M
- 04Rails 7.1 adds multi-column ordering to batch processingOctober 3, 2023 · Navaneeth D