The folks over at thoughtbot, inc. have released Jester, an almost identical port of Rails’ ActiveResource to JavaScript.

Here is some sample code showing associations (hijacked directly from the blog post):


>>> eric = User.find(1)
GET http://localhost:3000/users/1.xml
Object _name=User _singular=user _plural=users

>>> eric.posts
[Object _name=Post _singular=post _plural=posts, Object _name=Post _singular=post _plural=posts]

>>> eric.posts.first().body
"Today I passed the bar exam. Tomorrow, I make Nancy my wife."
>>> eric.posts.first().body = "Today I *almost* passed the bar exam. The ring waits one more day."
"Today I *almost* passed the bar exam. The ring waits one more day."

>>> eric.posts.first().save()
POST http://localhost:3000/posts/1.xml
true

>>> post = Post.find(1)
GET http://localhost:3000/posts/1.xml
Object _name=Post _singular=post _plural=posts

>>> post.body
"Today I *almost* passed the bar exam. The ring waits one more day."
>>> post.user
Object _name=User _singular=user _plural=users
>>> post.user.name
"Eric Mill"

Hop over to GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS (cool name eh?) for the full scoop, code, and to give those guys your feedback.

Comments

  1. MoXXian #

    I’m sorry to ignore your warning, but I have no google account and don’t plan to get one in the news few month. Anyway this is not a bug report.

    Some ppl are trying to compress/reduce the prototype framework in various ways. In my opinion the offical distributor should de this to achive a 100% compatible version to the none-compressed and nice idented/named version (which is bloated).

    I suggest to use not kinds of compression stuff who uses eval(..) because it encryptes or packs the whole thing. This is bad imho.

    Please release a OFFCIAL reduced size version of the framework, which uses more things like: no white spaces, one-letter local variables, class variables as Capital-one-letters and so forth. fIf the function/method names remain intact the framework should work like the ‘big’ one.

    Well in times of DSL 16.000 Mbit downspeed everyone should thing that this does not matter. But every Byte who does not need to be transfered speeds a website up. And if – let’s say – the reduced version is only 35K instead of 75K there are countries which will much more like Prototyped websites.

    So please consider an offical reduced size additional release always.

    April 5th, 2007 @ 04:32 AM
  2. Maurice Fonk #

    Inspired by Jester I wrote a little javascript library for using Zend_Db_Table based models in Javascript. I too based it on prototype.

    While there are some fundamental differences between RoR ActiveResource and Zend_Db_Table based models, some of their functionality is similar. And it’s very nice to be able to work with models on the client side like you would in a php script.

    http://naneau.nl/2007/04/17/introducing-jstable/ for more details.

    April 18th, 2007 @ 08:00 PM

Sorry, comments are closed for this article.

Search Blog


Search the prototype blog.

Subscribe to the blog

Akismet badge