Provides a set of helpers for calling JavaScript functions and, most importantly, to call remote methods using what has been labelled AJAX. This means that you can call actions in your controllers without reloading the page, but still update certain parts of it using injections into the DOM. The common use case is having a form that adds a new element to a list without reloading the page.

To be able to use the JavaScript helpers, you must include the Prototype JavaScript Framework and for some functions script.aculo.us (which both come with Rails) on your pages. Choose one of these options:

  • Use <%= javascript_include_tag :defaults %> in the HEAD section of your page (recommended): The 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 script.aculo.us-based JavaScript helpers, like visual effects, autocompletion, drag and drop and so on, you should use the method described above.
  • Use <%= define_javascript_functions %>: this will copy all the JavaScript support functions within a single script block.

For documentation on javascript_include_tag see ActionView::Helpers::AssetTagHelper.

If you’re the visual type, there’s an AJAX movie demonstrating the use of form_remote_tag.


CALLBACKS = [:uninitialized, :loading, :loaded, :interactive, :complete, :failure, :success].push((100..599).to_a).flatten

AJAX_OPTIONS = [ :before, :after, :condition, :url, :asynchronous, :method, :insertion, :position, :form, :with, :update, :script ].concat(CALLBACKS)

JAVASCRIPT_PATH = File.join(File.dirname(__FILE__), 'javascripts')


Show files where this module is defined (1 file)
Register or log in to add new notes.