instance method
remote_function
Ruby on Rails 2.3.18
Since v2.2.3 Last seen in v3.0.20Signature
remote_function(options)
Returns the JavaScript needed for a remote function. Takes the same arguments as link_to_remote.
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>
Parameters
-
optionsreq
Source
# File actionpack/lib/action_view/helpers/prototype_helper.rb, line 448
def remote_function(options)
javascript_options = options_for_ajax(options)
update = ''
if options[:update] && options[:update].is_a?(Hash)
update = []
update << "success:'#{options[:update][:success]}'" if options[:update][:success]
update << "failure:'#{options[:update][:failure]}'" if options[:update][:failure]
update = '{' + update.join(',') + '}'
elsif options[:update]
update << "'#{options[:update]}'"
end
function = update.empty? ?
"new Ajax.Request(" :
"new Ajax.Updater(#{update}, "
url_options = options[:url]
url_options = url_options.merge(:escape => false) if url_options.is_a?(Hash)
function << "'#{escape_javascript(url_for(url_options))}'"
function << ", #{javascript_options})"
function = "#{options[:before]}; #{function}" if options[:before]
function = "#{function}; #{options[:after]}" if options[:after]
function = "if (#{options[:condition]}) { #{function}; }" if options[:condition]
function = "if (confirm('#{escape_javascript(options[:confirm])}')) { #{function}; }" if options[:confirm]
return function
end
Defined in actionpack/lib/action_view/helpers/prototype_helper.rb line 448
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionView::Helpers::PrototypeHelper