This project is archived and is in readonly mode.
activeresource xml/json encoding inconsistency
Reported by Jan Berkel | April 8th, 2009 @ 02:03 PM | in 2.x
the activeresource encoding for xml/json seem to be inconsistent: xml will incude the element name as root
from activeresource/base.rb
self.class.format.encode(attributes, {:root => self.class.element_name})
whereas json will use
self.class.format.encode(attributes, options)
so when an activeresource gets saved, the decoded parameters (on the REST API side) are different, e.g.
{"city"=>nil, "name"=>"Foo Bar" } (JSON) vs.
{"person" => { "city=>nil, "name"=> "Foo Bar" } } (XML)
so when using json, i can't just use Person.find().update_attributes(params[:person]) in my controller.
is this intentional? looks like a bug.
Comments and changes to this ticket
-
Steve St. Martin April 16th, 2010 @ 12:12 AM
- Assigned user set to Ryan Bigg
this issue can be solved with:
ActiveRecord::Base.include_root_in_json = true
can be marked as invalid
-
Ryan Bigg April 16th, 2010 @ 01:25 AM
- State changed from new to resolved
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>