On Mar 2, 2012, at 10:17 PM, Mark Peterson wrote:
>
> ### Scenario 2 using remove_root in decode, user.json does not have "id" ###
>
> def decode(json)
> Formats.remove_root(ActiveSupport::JSON.decode(json))
> end
>
> GET /users/123.json
>
> "{\"image_page\":{\"images\":[{\"id\":123},{\"id\":456}],\"total\":2000,\"count\":2,\"start_index\":0}}"
>
> p user = #<User:0x00000101133cb8
> @attributes={"images"=>[#<Image:0x000001011327a0 @attributes={"id"=>123},
> @prefix_options={}, @persisted=false>, #<Image:0x00000103a49e40
> @attributes={"id"=>456}, @prefix_options={}, @persisted=false>],
> "total"=>2000, "count"=>2, "start_index"=>0}, @prefix_options={},
> @persisted=true>
This looks to be a variant of issue #2692:
https://github.com/rails/rails/pull/2692
although the patch in that instance wouldn't fix this bug, as the detection
heuristic will guess that image_page is a root element to be removed.
It appears that the problem is that remove_root doesn't have any awareness of
the context in which it's operating - really, we should only be removing the
appropriately-named root element (if it exists).
--Matt Jones
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.