Extends remote_function & link_to_remote so they support :replace as well as :update. Also adds :eval_or_update and :eval_or_replace to handle AJAX actions that sometimes return javascript, sometimes HTML.
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



This plugin extends remote_function (and so link_to_remote, form_remote_tag etc.)
so that it supports :replace (corresponding to Prototype's Element.replace) in
addition to the normal :update (which corresponds to Prototype's Element.update).

Particularly useful when you use render :collection with a partial that wraps
each object in the collection in its own DIV/TR/TD/whatever, as you often need to
replace the contents but would like to be able to reuse that same partial without
splitting it into wrapper & inner content partials.

There's also the handy :eval_or_update and eval_or_replace.  Since the vanilla
remote_function normally sets evalScripts:true, if the server returns a response
with a javascript content-type, the code will be executed.  Frustratingly however,
if you're using :update or :replace, in this case the javascript will _also_ be
put into the indicated div.  With :eval_or_update and :eval_or_replace, you get
more sensible behavior - if the response is javascript, it will be executed;
otherwise, it will update or replace the given div.


<%= link_to_remote 'Refresh row', customer_path(customer), :replace => dom_id(customer) %>
<%= link_to_remote 'Refresh row', customer_path(customer), :replace => {:success => dom_id(customer), :failure => "errors"} %>

Copyright (c) 2008-2009 Will Bryant, Sekuda Ltd, released under the MIT license