method

remote_function

rails latest stable - Class: ActionView::Helpers::PrototypeHelper

Method deprecated or moved

This method is deprecated or moved on the latest stable version. The last existing version (v3.0.9) is shown here.

remote_function(options)
public

Returns the JavaScript needed for a remote function. See the link_to_remote documentation at http://github.com/rails/prototype_legacy_helper as it takes the same arguments.

Example:

# Generates: <select id="options" onchange="new Ajax.Updater('options',
# '/testing/update_options', {asynchronous:true, evalScripts:true})">
<select id="options" onchange="<%= remote_function(:update => "options",
    :url => { :action => :update_options }) %>">
  <option value="0">Hello</option>
  <option value="1">World</option>
</select>

2Notes

Example

Vidmantas · Apr 16, 20093 thanks

This function can be used to pass the ID of selected item, for example:

# with select or collection_select helpers:
{ :onchange => remote_function(:url => { :action => 'do_smth' }, :with => "'id=' + $('the_id').value") }

# and grab ID in controller action as usually: 
YourModel.find(params[:id])

With multiple parameters

joni · Aug 13, 20093 thanks

=== Example remote_function( :url => some_remote_function_path, :with => "'key1='+$('elem_id').value +'&key2='+$('elem_id').value+ '&this_elem_value='+value" )