Associations in Jester, or What's going on with my Javascript?

1 view
Skip to first unread message

Nate

unread,
Feb 11, 2008, 3:00:27 AM2/11/08
to Jester JS
Has anyone been able to make associations work out of the box? The
Jester docs refer to functions like this:

// All comments for Post #1
Post.find(1).comments

// Kill the foolish user who owns Post #1 -- assumes DELETE request
to /users/1.xml
Post.find(1).user.destroy()

That's good and all, but calls like those in my environment do not
automatically model comments or make any calls to the
ActiveResources. In fact, nothing happens, which makes me wonder the
xml output I create through ActiveResource's native xml creation
doesn't render the information necessary for Jester to know that Post
should 'have_many' comments.

Anyone solve this one?

Thanks,
Nate

John Webb

unread,
Feb 11, 2008, 7:23:18 PM2/11/08
to jest...@googlegroups.com

The short answer is yes, it does work. As long as the Javascript entity
called "Post" refers to a class created by Jester then it will work.
Like most things there are a number of gotchas: Jester does not work
properly with IE7; issues can be caused by ruby/rails/Jester version
mismatches and your controllers must be set up to respond with xml ie

respond_to do |format|
format.html # show.rhtml
format.xml { render :xml => @subcat.to_xml }

I have Jester and raw Javascript working with a significant set of
hierarchical data structures and it works pretty well flawlessly.

John

Nate

unread,
Feb 14, 2008, 1:07:28 PM2/14/08
to Jester JS
Sorry, I'm still confused.

Jester, in FF, works great for me. Using FF, Rails 2.0.2 and the
ActiveResource out-of-the-box setup I can write things like:

Resource.model('Post');
var p = Post.find(1);

And then it ends. Let's say a Post has_many comments, I cannot write:

p.comments

Doing so returns nothing.

Do I need to model the Comment resource before I call this? Looking
at the Jester source, it looks like there is a built in way to
automatically model resources on the fly, but what's not clear to me
is how Jester is supposed to know that what you are calling is a model
('Comment' in this case) with a relationship to the primary model
('Post' in this case) at all. Shouldn't some information about the
relationship between Post and Comment be sent along in the
ActiveResource XML response? If not, how is Jester inferring the
relationship? Or is it just that I would need to, on the Rails side,
write something like

@post = Post.find(1, :include => [:comments])

Also, what are the known issues in IE7?

Thanks for your help and your responses,
Nate

Eric Mill

unread,
Feb 22, 2008, 12:57:09 PM2/22/08
to Jester JS
Jester infers as to whether something is a has_many relationship by
the structure of the XML. I think that in Rails 2, ActiveResource has
added an attribute to the parent element of associated elements drawn
in from a has_many relationship. This fundamentally alters the array
structure that ParseTree returns, causing a bug in Jester.

I've just created a Google Code page for Jester to allow us to track
issues like this so that they don't get lost in emails, as so many
have been recently. Would you mind creating an issue there? I'll be
paying fierce attention to the issue tracker while I get the
development momentum re-rolling here.

http://code.google.com/p/jester-js/

Thanks,
Eric
Reply all
Reply to author
Forward
0 new messages