Speaking of recent Rails + Jester problems

1 view
Skip to first unread message

Nat Budin

unread,
Aug 22, 2008, 4:49:15 PM8/22/08
to jest...@googlegroups.com
Somewhere along the line - I'm guessing in Rails 2.1 - the behavior of
ActiveRecord::Base#to_json seems to have changed. I'll give an
example - previously, doing something like user.to_json would have
returned something like:

{"nickname": "",
"lastname": "Budin",
"id": 35,
"gender": "male",
"firstname": "Nat",
"created_at": "2007-03-11T17:31:18Z",
"updated_at": "2008-08-22T20:13:45Z"}

But now instead, it returns:

{"user":
{"nickname": "",
"lastname": "Budin",
"id": 35,
"gender": "male",
"firstname": "Nat",
"created_at": "2007-03-11T17:31:18Z",
"updated_at": "2008-08-22T20:13:45Z"}}

Jester isn't designed to understand this format. I managed to hack
the _attributesFromJSON method to work with this - basically, adding
another case where the attribute name is the same as the class name -
but I'm not sure it's the right approach. On the Rails side, you can
instead do user.attributes.to_json instead of user.to_json.

I don't particularly love the Jester-side hack that I did, but perhaps
there is a better way to do the same thing without having to modify
the Rails code...?

Nat

Eric Mill

unread,
Aug 22, 2008, 5:06:05 PM8/22/08
to jest...@googlegroups.com
Interesting. I think Jester should just commit to supporting the latest
standard, and forget about supporting the old attributes-only one. The
new JSON standard is closer to the XML standard, anyway.

-- Eric

Reply all
Reply to author
Forward
0 new messages