when displaying an image in Rails, but use video_tag` when you want to play a video.
But why doesn't the video play?
By the way, the official Rails documentation is below.
Rails official document [video_tag]
<% @posts.each do |post| %> <%= video_tag(post.movie, size: "500x300", autoplay: true) %> <% end %>
The data is taken from the movie column of the posts table. If you specify the video size as 500x300 and set ʻautoplay: true`, it should be played automatically, but it will not be played.
As you can see from the official Rails documentation, there is an option called
The default is
muted: folse, which means that audio playback is performed.
It seems that Chrome will not autoplay unless both ʻautoplay
are enabled, as it will be a burden to the user if the audio etc. starts to play automatically. The description withmuted` added is as follows.
<% @posts.each do |post| %> <%= video_tag(post.movie, size: "500x300", autoplay: true, muted: true) %> <% end %>
Thank you for reading. I hope it helps someone to play the video.