The documentation on to_json says that serialization outputs just the attributes hash as json from an AR record http://api.rubyonrails.org/classes/ActiveRecord/Serialization.html#M001826 That suggests that if I did something like Account.find(:first).to_json I''d get something like {"name": ...} However I''m looking at several version of rails apps (2.2 and edge/ 2.3) from the console and if I do something like Account.find(:first).to_json I get something more akin to {"account": {"name" : ...}} I''m not sure which one is right and which one is wrong. It''s also worth noting that if ActiveResource gets the second type as a response, it actually creates an incorrect Account object where attributes hash contains the proper Account object. ActiveResource appears to require the response listed in the documentation although I haven''t seen that being generated. Just a note, I removed all my JSON gems just in case there was some kind of conflict. What''s going on here, am I just overlooking something? Josh Ferguson --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
On 12 Feb 2009, at 08:31, Josh Ferguson wrote:> > {"account": {"name" : ...}} > > I''m not sure which one is right and which one is wrong. > > It''s also worth noting that if ActiveResource gets the second type as > a response, it actually creates an incorrect Account object where > attributes hash contains the proper Account object. ActiveResource > appears to require the response listed in the documentation although I > haven''t seen that being generated. > > Just a note, I removed all my JSON gems just in case there was some > kind of conflict. > > What''s going on here, am I just overlooking something? >I believe this is tied up with ActiveRecord::Base.include_root_in_json (which in a newly generated rails app is set to true by an initializer) Fred> Josh Ferguson > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Is there a reason activeresource doesn''t parse the default json output properly? Is there an option in activeresource there we can set to match the default output? This was pretty frustrating for me as it seemed like it should "just work" but doesn''t. Also it seems like the correct thing here is to just have activeresource recognize root elements properly. Josh Ferguson On Feb 12, 2009, at 3:20 AM, Frederick Cheung wrote:> > > On 12 Feb 2009, at 08:31, Josh Ferguson wrote: >> >> {"account": {"name" : ...}} >> >> I''m not sure which one is right and which one is wrong. >> >> It''s also worth noting that if ActiveResource gets the second type as >> a response, it actually creates an incorrect Account object where >> attributes hash contains the proper Account object. ActiveResource >> appears to require the response listed in the documentation >> although I >> haven''t seen that being generated. >> >> Just a note, I removed all my JSON gems just in case there was some >> kind of conflict. >> >> What''s going on here, am I just overlooking something? >> > I believe this is tied up with ActiveRecord::Base.include_root_in_json > (which in a newly generated rails app is set to true by an > initializer) > > Fred >> Josh Ferguson >> >>> > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Josh Ferguson wrote:> Is there a reason activeresource doesn''t parse the default json output > properly? Is there an option in activeresource there we can set to > match the default output? This was pretty frustrating for me as it > seemed like it should "just work" but doesn''t. Also it seems like the > correct thing here is to just have activeresource recognize root > elements properly.This definitely seems it''s worth adding a new lighthouse ticket targetting 2.3. Round tripping is key point with ARes. -- Cheers, Koz --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---