Skip to content

Instantly share code, notes, and snippets.

@remvee
Created December 4, 2009 15:42
Show Gist options
  • Save remvee/249082 to your computer and use it in GitHub Desktop.
Save remvee/249082 to your computer and use it in GitHub Desktop.
JS App.with_resource
// Usage: App.with_resource('user', 567, function(user) { $('report_user_name').value = user.name })
var App = {
with_resource: function(name, id, func) {
new Ajax.Request("/" + name + "s/" + id + ".json", {
method: 'GET',
onSuccess: function(transport) { func(transport.responseJSON[name]) }
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment