Mike Bailey

simply jestful

Filed under: ruby on rails, javascript — Mike Bailey @ 7:29 am on August 5, 2007

Update: I’m using jester.js version 1.3.

Jester is basically ActiveResource for javascript. It’s amazing. I love it! With *almost* no changes to my scaffold_resource generated controllers I was able to work on my models via javascript in my web browser.

All I had to do was download the javascript and put it in public/javascripts/

I put this in my layout: <%= javascript_include_tag 'jester.js' %>

Then I was able to do this in Firebug:

>>> Base.model('User')
>>> Base.model('Comment')
>>> c = Comment.create({comment: 'i love jester'})
POST http://localhost:3000/comments.xml (381ms)prototype.js (line 866)
Object _name=Comment _format=xml _singular=comment
>>> c.id
12
>>> c.user
Object _name=User _format=xml _singular=user _plural=users
>>> c.user.display_name
"Mike"

Use XML, not JSON. The Rails implementation of .to_json() is not as fully featured as .to_xml().

This patch was accepted into core in June. I used it to patch my rails-1.2.3 installation. It stops the following from failing:

format.xml { render :xml => @post.to_xml(:include => :comments, :methods => [:obfuscated_email]) }

Jester is documented in a series of release announcement blog posts. I recommend reading them in order.

2 Comments »

  1. You gave an excellent presentation on Jester at the recent Melbourne Ruby User Group meeting http://tinyurl.com/2j3hqu

    Would you consider posting your slides and demo app from that presentation?

    Comment by Gus Gollings — October 3, 2007 @ 5:14 am

  2. I’ve uploaded the slides here:

    http://mike.bailey.net.au/blog/?p=18

    Comment by Mike Bailey — October 3, 2007 @ 7:36 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

Copyright 2007 Mike Bailey. All Rights Reserved