Method: ActionView::Helpers::PrototypeHelper#remote_function
- Defined in:
- lib/action_view/helpers/prototype_helper.rb
#remote_function(options) ⇒ Object
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>
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 |
# File 'lib/action_view/helpers/prototype_helper.rb', line 448 def remote_function() = () update = '' if [:update] && [:update].is_a?(Hash) update = [] update << "success:'#{[:update][:success]}'" if [:update][:success] update << "failure:'#{[:update][:failure]}'" if [:update][:failure] update = '{' + update.join(',') + '}' elsif [:update] update << "'#{[:update]}'" end function = update.empty? ? "new Ajax.Request(" : "new Ajax.Updater(#{update}, " = [:url] = .merge(:escape => false) if .is_a?(Hash) function << "'#{escape_javascript(url_for())}'" function << ", #{})" function = "#{[:before]}; #{function}" if [:before] function = "#{function}; #{[:after]}" if [:after] function = "if (#{[:condition]}) { #{function}; }" if [:condition] function = "if (confirm('#{escape_javascript([:confirm])}')) { #{function}; }" if [:confirm] return function end |