Provides functionality for working with JavaScript in your views.
For information on using Ajax, see ActionView::Helpers::PrototypeHelper.
For information on using controls and visual effects, see ActionView::Helpers::ScriptaculousHelper.
Rails includes the Prototype JavaScript framework and the Scriptaculous JavaScript controls and visual effects library. If you wish to use these libraries and their helpers (ActionView::Helpers::PrototypeHelper and ActionView::Helpers::ScriptaculousHelper), you must do one of the following:
Use <%= javascript_include_tag :defaults %> in the HEAD section of your page (recommended): This function will return references to the JavaScript files created by the rails command in your public/javascripts directory. Using it is recommended as the browser can then cache the libraries instead of fetching all the functions anew on every request.
Use <%= javascript_include_tag 'prototype' %>: As above, but will only include the Prototype core library, which means you are able to use all basic AJAX functionality. For the Scriptaculous-based JavaScript helpers, like visual effects, autocompletion, drag and drop and so on, you should use the method described above.
For documentation on javascript_include_tag see ActionView::Helpers::AssetTagHelper.
Escape carrier returns and single and double quotes for JavaScript segments.
# File lib/action_view/helpers/javascript_helper.rb, line 50 50: def escape_javascript(javascript) 51: if javascript 52: javascript.gsub(/(\\|<\/|\r\n|[\n\r"'])/) { JS_ESCAPE_MAP[$1] } 53: else 54: '' 55: end 56: end
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