[RUBY] [Rails] Video does not play with video_tag

Rails video_tag implementation

Use ʻimage_tag 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]

Description that does not play

<% @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.

Cause and code addition

As you can see from the official Rails documentation, there is an option called muted. The default is muted: folse, which means that audio playback is performed. It seems that Chrome will not autoplay unless both ʻautoplay and mutedare 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 %>

in conclusion

Thank you for reading. I hope it helps someone to play the video.

Recommended Posts

[Rails] Video does not play with video_tag
Bundle install with docker + rails6 does not reflect gem
When the server does not start with rails s
Container does not start with docker-compose
JavaScript (vanilla) does not respond in Rails.
[Rails] Could not locate Gemfile with bundle install
[Rails] Bootstrap form-control does not apply to date_select
rails new app is not created with app name
I want to play with Firestore from Rails
Localhost3000 does not start up in Docker / Rails development.
[How to insert a video in haml with Rails]
Docker Compose does not start with docker.credentials.errors.InitializationError error message
Terminal does not start
Rails deploy with Docker
[Rails 6] RuntimeError with $ rails s
Handle devise with Rails
[Rails] Learning with Rails tutorial
[Rails] Test with RSpec
[Rails] Development with MySQL
Supports multilingualization with Rails!
Sidekiq-limit_fetch does not work
Double polymorphic with Rails
[Ruby on Rails] When parameter id acquisition does not work
[Rails] Couldn't find with'id'=: id does not execute update action
[Rails] The problem that pry-byebug does not stop through breakpoints
What to check when rails db: migration does not pass
[Rails] Solving the problem that session timeout does not work