ActionView::Helpers::JavaScriptHelper
def javascript_tag(content_or_options_with_block = nil, html_options = {}, &block)

Description

Creates a <script> with JavaScript as its content.

Arguments

Changing a value updates the ERB and HTML.

Used as the content of the <script>, wrapped in a //<![CDATA[ line and a //]]> line. The content is not escaped.
html_options= {}
"module"
Sets the type attribute.
true sets nonce to the CSP nonce. This site does not configure CSP, so nothing is added. false adds no nonce attribute, and a string is used as the value.
Common options

Rails handles these options the same way in every helper. Options the HTML spec does not allow on the <script>, 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 html_options become HTML attributes of the <script>; those with a nil value are left out.

ERB

Changes from the previous output: Added Removed Changed


          

HTML