PrototypeHelper

PrototypeHelper provides a set of helpers for calling Prototype JavaScript functions, including functionality to call remote methods using 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.

The following is a list of helpers:

evaluate_remote_response()

Returns eval(request.responseText), which is the JavaScript function that form_remote_tag can call in :complete to evaluate a multiple-update return document using update_element_function calls.

form_remote_for(object_name, object, options = {}, &proc)

Alias for remote_form_for.

form_remote_tag(options = {})

Returns a form tag that will submit using XMLHttpRequest in the background instead of the regular reloading POST arrangement. Even though it’s using JavaScript to serialize the form elements, the form submission will work just like a regular submission as viewed by the receiving side (all elements available in @params). The options for specifying the target with :url and defining callbacks is the same as link_to_remote.

A fall-through target for browsers that doesn’t do JavaScript can be specified with the :action or:method options on :html.

Example:

form_remote_tag :html => { :action => url_for(:controller => 
  "some", :action => "place") }

The hash passed to the :html key is equivalent to the options (second) argument in ...

Get Rails Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.