module ActionView::Helpers::JavaScriptHelper

def escape_javascript(javascript)

$('some_element').replaceWith('<%= j render 'some/element_template' %>');

responses, like:
Also available through the alias j(). This is particularly helpful in JavaScript

Escapes carriage returns and single and double quotes for JavaScript segments.
def escape_javascript(javascript)
  javascript = javascript.to_s
  if javascript.empty?
    result = ""
  else
    result = javascript.gsub(/(\\|<\/|\r\n|\342\200\250|\342\200\251|[\n\r"']|[`]|[$])/u, JS_ESCAPE_MAP)
  end
  javascript.html_safe? ? result.html_safe : result
end

def javascript_cdata_section(content) # :nodoc:

:nodoc:
def javascript_cdata_section(content) # :nodoc:
  "\n//#{cdata_section("\n#{content}\n//")}\n".html_safe
end

def javascript_tag(content_or_options_with_block = nil, html_options = {}, &block)

<% end -%>
alert('All is good')
<%= javascript_tag nonce: true do -%>

nonce value by passing nonce: true as part of +html_options+. Example:
If you have a content security policy enabled then you can add an automatic

<% end -%>
alert('All is good')
<%= javascript_tag type: 'application/javascript' do -%>

in which case, you pass your +html_options+ as the first parameter.
Instead of passing the content as an argument, you can also use a block


//]]>
alert('All is good')
//
//]]>
alert('All is good')
//