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. See the link_to_remote documentation at 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 => "",
:url => { :action => :update_options }) %>">
<option value="0">Hello</option>
<option value="1">World</option>
</select>
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/action_view/helpers/prototype_helper.rb', line 115 def remote_function() = () update = '' if [:update] && [:update].is_a?(Hash) update = [] update << "success:'#{options[:update][:success]}'" if [:update][:success] update << "failure:'#{options[:update][:failure]}'" if [:update][:failure] update = '{' + update.join(',') + '}' elsif [:update] update << "'#{options[:update]}'" end function = update.empty? ? "new Ajax.Request(" : "new Ajax.Updater(#{update}, " = [:url] function << "'#{html_escape(escape_javascript(url_for(url_options)))}'" function << ", #{javascript_options})" function = "#{options[:before]}; #{function}" if [:before] function = "#{function}; #{options[:after]}" if [:after] function = "if (#{options[:condition]}) { #{function}; }" if [:condition] function = "if (confirm('#{escape_javascript(options[:confirm])}')) { #{function}; }" if [:confirm] return function.html_safe end |