ActionView::Helpers::AssetTagHelper
def video_tag(*sources)

Description

Creates a <video>.

Arguments

Changing a value updates the ERB and HTML.

Used as the src attribute. Depending on the value:
  • A URL (a string starting with https:// or another …://, //, data: or cid:): used as is.
  • A string starting with / ("/movie.mp4"): used as is.
  • Any other string ("clip.mp4"): looks up the asset (a file in app/assets) and uses its path, with a digest added to the file name. If the asset is not found, raises Propshaft::MissingAssetError. The lookup and digest come from Propshaft; in an app without an asset pipeline, it just prepends /videos/ to the path.
= nil
"/movie.webm"
The second and later sources. With two or more sources, puts a <source> for each inside the <video> instead of setting its src. This page lets you try up to the second.
options= {}
true adds controls="controls". This page passes it initially so that the preview shows a player.
"logo.png"
Sets the poster attribute. As with *sources, a string that is neither a URL nor starts with / is looked up as an asset.
true skips the asset lookup for poster and prepends /images/ to the path.
"320x240"
As with image_tag, splits "320x240" into the width and height attributes. Unlike image_tag, also passing width or height does not raise ArgumentError; the values from size override them (if size is not in this form, the given width and height are dropped too).
true skips the asset lookup and prepends /videos/ to the path.
Common options

Rails handles these options the same way in every helper. Options the HTML spec does not allow on the <video>, and ones this site considers rarely used, are not listed here.

Shared by all helpers

{active: true, hidden: false}
A hash gives the keys whose values are not false or nil, joined with spaces. An array gives its elements joined with spaces, after removing nil, false and empty strings (including whitespace-only strings).
{controller: "tags", tags_suggestions_value: ["ruby", "rails"]}
A hash adds data-* attributes, with _ in the keys converted to -. Array and hash values are converted to JSON strings.
{describedby: ["name_help", "name_error"], invalid: false}
Like :data, adds aria-* attributes. Array values are joined with spaces, leaving out nil and empty strings (nothing is added if none remain). For a hash value, the keys whose values are not false or nil are joined with spaces.
Any other options become HTML attributes of the <video>; those with a nil value are left out.

ERB

Changes from the previous output: Added Removed Changed


          

HTML


          

Preview