Nate
unread,Feb 3, 2008, 3:17:16 PM2/3/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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) {}