Method: ActionView::Helpers::JavaScriptHelper#javascript_tag

Defined in:
lib/action_view/helpers/javascript_helper.rb

#javascript_tag(content, html_options = {}) ⇒ Object

Returns a JavaScript tag with the content inside. Example:

javascript_tag "alert('All is good')"

Returns:

<script type="text/javascript">
//<![CDATA[
alert('All is good')
//]]>
</script>

html_options may be a hash of attributes for the <script> tag. Example:

javascript_tag "alert('All is good')", :defer => 'true' # => <script defer="true" type="text/javascript">alert('All is good')</script>


168
169
170
# File 'lib/action_view/helpers/javascript_helper.rb', line 168

def javascript_tag(content, html_options = {})
  ("script", javascript_cdata_section(content), html_options.merge(:type => "text/javascript"))
end