Mike Bailey gave a presentation on a Javascript library called Jester to the Melbourne Ruby Users Group. Here are the slides. They contain mostly working code.
14. # new
# note, reflection available but not turned on by default
# rails patch by jesters author has been accepted into core
property = Property.build(
{name: 'Kevin', address: '40 The Avenue, Windsor'} );
property.id; # => null
property.save();
property.id; # => 4
20. # reload a model
property.reload();
# can cause problems if your object has associations
# as it recreates objects - existing references to
# the associated objects are orphaned
22. class PropertyController < ApplicationController
# GET /properties
# GET /properties.xml
def index
respond_to do |format|
format.html # index.rhtml
format.xml {
render :xml => @properties.to_xml(
:include => [:subscriptions], # associated models
:methods => [:amount_owing] # call these methods
)
}
end
end
23. Other Tips
Use Rails’s .to_xml, not .to_json
Changeset 7156
Patch in core for .to_xml clash
between :include & :methods
24. more info
• jester is documented in three blog posts
• http://giantrobots.thoughtbot.com/
• I’ve linked to them on my blog
• http://mike.bailey.net.au/blog/?p=15