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 => "options",
:url => { :action => :update_options }) %>">
<option value="0">Hello</option>
<option value="1">World</option>
</select>
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/action_view/helpers/prototype_helper.rb', line 122 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] function << "'#{ERB::Util.html_escape(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.html_safe end |