Skip to content

Instantly share code, notes, and snippets.

@adamhjk
Created August 12, 2008 00:02
Show Gist options
  • Save adamhjk/4972 to your computer and use it in GitHub Desktop.
Save adamhjk/4972 to your computer and use it in GitHub Desktop.
class MonkeyController < Application
provides :html, :json
def index
@monkey_list = Monkey.list
if params[:partial] == "true"
display @node_list, :template => "foobar" # this is probably wrong
else
display @node_list
end
end
def show
begin
@node = Monkey.load(params[:id])
rescue Net::HTTPServerException => e
raise NotFound, "Cannot load monkey #{params[:id]}"
end
display @monkey
end
end
class Monkey
def list
[ :one, :two, :three ]
end
end
<html>
<...jquery setup stuff..>
<...livequery stuff..>
<script>
$(function() {
/* submit a form via XHR */
$("form.remote_form").livequery(
function() {
var to_update = "#" + $(this).attr('update');
var spinner_id = "#" + $(this).attr('id') + "_spinner";
$(this).ajaxForm({
dataType: 'html',
beforeSubmit: function() { $(spinner_id).show(); },
beforeSend: function(xhr) {
xhr.setRequestHeader("Accept", "text/html");
},
success: function(data) {
$(to_update).html(data);
$(spinner_id).hide();
}
});
}
);
}
</script>
<form class="remote_form" action="/monkey?partial=true" update="monkeylist">
<input type="submit" value="Show more monkeys">
</form>
<div id="monkeylist">
</div>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment