Speaking of recent Rails + Jester problems

Visto 1 vez
Saltar al primer mensaje no leído

Nat Budin

no leída,
22 ago 2008, 16:49:1522/8/08
a 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

no leída,
22 ago 2008, 17:06:0522/8/08
a 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

Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos