Created
August 12, 2008 00:02
-
-
Save adamhjk/4972 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Monkey | |
def list | |
[ :one, :two, :three ] | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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