Patch: Jester should handle <elem type="nil"> elements correctly

0 views
Skip to first unread message

Nate

unread,
Feb 3, 2008, 3:17:16 PM2/3/08
to Jester JS
Environment:
Rails 2.0.2
Prototype 1.6
Jester 1.5

I was having trouble making Jester calls which should have produced an
array of objects. Here is an example:

Resource.model("Foo");
var foos = Foo.find("all");

The AJAX request was going through properly, and ActiveResource was
returning well formed XML via @foo.to_xml. Some debugging showed that
Jester was hitting elements who had an attribute called "nil" set to
"true" and barfing. Jester would attempt to interpret them as
associations. Here's an example of one of the elements:

<place-guess nil="true"/>

I believe this issue was brought up elsewhere on this message board.
Someone reported having trouble parsing an array of objects when using
Jester's XML parsing, but not JSON parsing. I had a similar
experience, XML arrays didn't work, JSON arrays worked great. I'm not
sure why this only occurred when an array of XML objects was
requested, and not a single XML object but here is my patch
regardless:

Index: jester.js
===================================================================
--- jester.js (revision 120)
+++ jester.js (working copy)
@@ -329,6 +329,12 @@
else
value = undefined;
}
+ // This is to avoid ActiveRecord dumping nil values as <foo
type="nil">
+ // and Jester's inability to parse the nil value
+ else if (elements[attr] && elements[attr]["@nil"]) {
+ if (elements[attr]["@nil"] == "true") // make sure nil is
returning true
+ value = null; // null because it's not undefined
+ }

// handle empty value (pass it through)
if (!value) {}

Nate

unread,
Feb 3, 2008, 3:18:24 PM2/3/08
to Jester JS
Apologies, this thread should be titled:

Re: Patch: Jester should handle <elem nil="true"> elements correctly

n8

Eric Mill

unread,
Feb 22, 2008, 1:53:33 PM2/22/08
to Jester JS
Hi Nate,

This is a great bug report and patch. Would you mind turning this
into an issue on the tracker?
http://code.google.com/p/jester-js/issues/entry

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