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

Description

Creates an <audio>.

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 / ("/sound.mp3"): used as is.
  • Any other string ("chime.mp3"): 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 /audios/ to the path.
= nil
"/sound.ogg"
The second and later sources. With two or more sources, puts a <source> for each inside the <audio> 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.
true skips the asset lookup and prepends /audios/ to the path.
Common options

Rails handles these options the same way in every helper. Options the HTML spec does not allow on the <audio>, 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 <audio>; those with a nil value are left out. Unlike video_tag, size, poster and poster_skip_pipeline also become HTML attributes as is.

ERB

Changes from the previous output: Added Removed Changed


          

HTML


          

Preview