[RUBY] [Rails] How to use video_tag to display videos

We have realized the image & video upload function using carrierwave. Since I used "video_tag" for video display for the first time, I will keep it as a memorandum. I hope it helps some Rails beginners.


MacOS Catalina Rails Ruby 2.6.3

What is video_tag

スクリーンショット 2020-09-02 18.22.19.png The one that is often used when displaying videos like this. Think of it as a video version of image_tag.

Frequently used attributes

attribute meaning
autoplay Whether to play automatically after loading the page
controls Whether to show the controller
autobuffer Whether to buffer automatically
muted Whether to make a sound
size Specify size
width Specify width
height Specify height

Usage sample


<%= video_tag post.video.url, height: "50%", width: "50%" controls: true, autobuffer: true %>

It seems that it is essential to specify the size with size, width, or height. Videos taken with the camera are displayed in a ridiculously large range on the browser, and videos taken with the smartphone are vertically long. And why does the controller not come out if the width is narrowed only for the video taken with the smartphone ... (playback is possible)

At the end

It may be smarter to display thumbnails like Twitter and then have the user press the play button. I don't know how to achieve it. .. ..

Recommended Posts

[Rails] How to use video_tag to display videos
[Rails] How to use enum
How to use rails join
[Rails] How to use authenticate_user!
[Rails] How to use Scope
[Rails] How to use gem "devise"
[Rails] How to use devise (Note)
[Rails] How to use flash messages
[rails] How to display db information
How to use Ruby on Rails
[Rails] How to use Active Storage
[Introduction to Rails] How to use render
How to use custom helpers in rails
[Ruby on Rails] How to use CarrierWave
[Rails] How to use rails console with docker
[Rails] How to use ActiveRecord :: Bitemporal (BiTemporalDataModel)
[Rails] How to use the map method
[Rails] How to display error messages individually
How to use MySQL in Rails tutorial
[Ruby on Rails] How to use redirect_to
[Note] How to use Rails 6 Devise + cancancan
[Rails] How to use helper method, confimartion
How to use credentials.yml.enc introduced in Rails 5.2
How to use Map
How to write Rails
How to use rbenv
How to use letter_opener_web
How to use with_option
How to use fields_for
How to use java.util.logging
How to use map
How to use collection_select
How to use Twitter4J
How to use active_hash! !!
How to use MapStruct
How to use hidden_field_tag
How to use TreeSet
[How to use label]
How to use identity
How to use hashes
How to use JUnit 5
How to use Dozer.mapper
How to use Gradle
How to use org.immutables
How to use java.util.stream.Collector
How to use VisualVM
How to use Map
[Ruby on Rails] How to display error messages
[Rails] How to use select boxes in Ransack
How to use rails g scaffold, functions, precautions
How to use JQuery in js.erb of Rails6
[Rails] How to use Gem'rails-i18n' for Japanese support
[Ruby on Rails] How to use session method
[Rails] How to use PostgreSQL in Vagrant environment
[Rails] How to convert UC time display to Japanese time display
[Java] How to use Map
How to set the display time to Japan time in Rails
How to use Chain API
[Rails, JS] How to implement asynchronous display of comments
How to use java Optional
How to use JUnit (beginner)