[RUBY] [How to insert a video in haml with Rails]

If you can insert a video, you can decorate your website in a fashionable and cool way. This time I will explain in detail how to insert a video into haml with Rails.

Create a videos folder in the public folder

Click Create New Folder in a text editor to create a video folder under public.

Put the video file you want to insert under the video folder

Bring the video file you want to use under the video folder.

At this time, use mp4 </ font> ** as the extension of the video file! This is because most browsers currently support mp4. This time, we will use a file with the extension mp4, sample_video.mp4.

Describe the following in haml


= video_tag("/videos/sample_video.mp4", autoplay: true, loop: true, muted: true, class: 'video')

I will explain one by one. = video_tag It is possible to recall video files using video tags.

/videos/sample_video.mp4 Specify the folder to refer to.

autoplay: true It will be possible to play automatically when the page is refreshed.

loop: true At the end of the video, it will play repeatedly from the beginning.

muted: true It will be played silently.

Then the video will be displayed on the website like this! sample_video.mp4

Like this time, if you specify the class, you can change the layout of the video with scss!

At the end

Inserting a video was relatively easy, but it took me a while to make a video because it was my first time lol The video was created with iMovie on Mac!

** As a caveat If the size of the video file is too large, it will not be displayed, so save it as small as possible. ** **

Please refer to this article and insert a video to create a stylish and cool website!

Referenced articles [Video tag] Thorough summary of how to embed a video in HTML (site is written in HTML) https://webliker.info/52510/

Recommended Posts

[How to insert a video in haml with Rails]
How to insert a video in Rails
How to insert a video
How to rename a model with foreign key constraints in Rails
How to implement a like feature in Rails
How to easily create a pull-down in Rails
How to make a follow function in Rails
[Rails] How to log in with a name by adding a devise name column
How to implement a like feature in Ajax in Rails
How to delete a new_record object built with Rails
How to manually generate a JWT with Rails Knock
How to write a date comparison search in Rails
How to query Array in jsonb with Rails + postgres
[Rails 6] How to set a background image in Rails [CSS]
[Rails] How to load JavaScript in a specific view
How to get started with creating a Rails app
How to store data simultaneously in a model associated with a nested form (Rails 6.0.0)
[Rails] How to write in Japanese
How to introduce jQuery in Rails 6
How to get along with Rails
How to install Swiper in Rails
How to display a graph in Ruby on Rails (LazyHighChart)
Mapping to a class with a value object in How to MyBatis
How to set up a proxy with authentication in Feign
How to deal with errors in Rails s could not find a JavaScript runtime.
How to implement search functionality in Rails
How to change app name in rails
How to use custom helpers in rails
[Rails] How to convert from erb to haml
How to make a jar file with no dependencies in Maven
[Rails] How to use rails console with docker
How to use MySQL in Rails tutorial
How to run a job with docker login in AWS batch
Steps to set a favicon in Rails
How to get boolean value with jQuery in rails simple form
[rails] How to configure routing in resources
[rails] How to create a partial template
How to implement ranking functionality in Rails
How to publish a library in jCenter
How to use credentials.yml.enc introduced in Rails 5.2
How to build Rails 6 environment with Docker
How to implement a slideshow using slick in Rails (one by one & multiple by one)
How to create a query using variables in GraphQL [Using Ruby on Rails]
[Personal memo] How to interact with a random number generator in Java
How to update user edits in Rails Devise without entering a password
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
[Rails] How to get the user information currently logged in with devise
How to display the text entered in text_area in Rails with line breaks
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
[Java] [For beginners] How to insert elements directly in a 2D array
[Rails] How to apply the CSS used in the main app with Administrate
How to start a Docker container with a volume mounted in a batch file
How to insert processing with any number of elements in iterative processing in Ruby
Rails: How to write a rake task nicely
Convert to a tag to URL string in Rails
[Rails] How to write when making a subquery
[Rails] rails new to create a database with PostgreSQL
[Rails] How to create a graph using lazy_high_charts
[Rails] How to use select boxes in Ransack
How to translate Rails into Japanese in general
How to prevent direct URL typing in Rails