JavaScript Editor Free JavaScript Editor     JavaScript Debugger 

Main Page

Previous Page
Next Page

13.5. Whither Ajax?

Considering the number of goodies built into the Rails API, finding exactly where the Ajax functionality is hidden could take a little work. However, because I'm really crumby at keeping secrets, I'll spill the beans; everything that we're interested in is in the JavaScriptHelper module, as Table 13-1 shows.

Table 13-1. JavaScriptHelper Methods




Includes all the JavaScriptHelper's JavaScript functions in the page.

draggable_element (element_id, options = {})

Makes the element with the corresponding ID draggable.

drop_receiving_element (element_id, options = {})

Forces the dropping (drag and drop) of an element. Also makes an Ajax call.


Escapes the provided JavaScript.


Creates a JavaScript function that can evaluate a document returned from the server.

form_remote_tag(options = {})

Creates an HTML form that will be submitted using the XMLHttpRequest object.


Creates a JavaScript HTML tag/end tag that contains the provided content.

link_to_function(name, function, html_options = {})

Creates a hyperlink that links to a client-side JavaScript function.

link_to_remote(name, options = {}, html_options = {})

Creates a hyperlink that links to the server via an asynchronous XMLHttpRequest request.

observe_field(field_id, options = {})

Watches a field with the provided ID for user changes.

observe_form(form_id, options = {})

Watches the form with the provided ID for user changes.

periodically_call_remote (options = {})

Calls a provided URL whenever the interval elapses. If no interval is provided, a default of 10 seconds is used.


Returns a JavaScript snippet necessary for a remote function.

sortable_element(element_id, options = {})

Alters the HTML element with the corresponding element_id so that the element is sortable via an Ajax call.

submit_to_remote(name, value, options = {})

Displays a button that submits a form using the XMLHttpRequest object asynchronously.

update_element_function (element_id, options = {}, &block)

Updates the browser's DOM using the passed arguments.

visual_effect(name, element_id = false, js_options = {})

Returns JavaScript code that uses Ajax callbacks for visual effects.

Because I find myself in pretty much the same situation as one of the professors when I went to collegeat least, as far as Ruby on Rails is concernedI'm putting off an example of Ajax using Ruby on Rails until Chapter 14, "Traveling Farther with Ruby." The reason for this is that I'm a little out of my comfort zone here; like the professor, I'm essentially taking a class during the day and teaching it at night.

Previous Page
Next Page

JavaScript Editor Free JavaScript Editor     JavaScript Debugger