I''m doing a request from a Rails app to another Rails app with ActiveResource. When the format on ActiveResource is XML: Content.find(:all)[0,2].map(&:attributes) => [ {"updated_at"=>Mon Apr 27 15:04:32 UTC 2009, "url"=>"www.google.com", "id"=>1, "created_at"=>Mon Apr 27 15:04:32 UTC 2009}, {"updated_at"=>Tue Apr 28 14:48:55 UTC 2009, "url"=>"www.google.com", "id"=>2, "created_at"=>Tue Apr 28 14:48:55 UTC 2009} ] Nice and smooth. But when it is JSON: Content.find(:all)[0,2].map(&:attributes) => [ {"content"=>#<Content:0x2040d10 @prefix_options={}, @attributes{"updated_at"=>"2009-04-27T15:04:32Z", "url"=>"www.google.com", "id"=>1, "created_at"=>"2009-04-27T15:04:32Z"}>}, {"content"=>#<Content:0x2040248 @prefix_options={}, @attributes{"updated_at"=>"2009-04-28T14:48:55Z", "url"=>"www.google.com", "id"=>2, "created_at"=>"2009-04-28T14:48:55Z"}>} ] the problem is that to get an attribute in each Content object I have to do object.content.url instead of plain content.url. Why is this happening? Is there any workaround?
Paulo Pereira
2009-Apr-30 16:56 UTC
Re: Different behaviour on ActiveResorce with JSON or XML
Should it be better to post in the Rails Lighthouse? On Apr 29, 12:59 pm, Paulo Pereira <paulo.z...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m doing a request from a Rails app to another Rails app with > ActiveResource. > > When the format on ActiveResource is XML: > > Content.find(:all)[0,2].map(&:attributes) > => [ > {"updated_at"=>Mon Apr 27 15:04:32 UTC 2009, > "url"=>"www.google.com", "id"=>1, "created_at"=>Mon Apr 27 15:04:32 > UTC 2009}, > {"updated_at"=>Tue Apr 28 14:48:55 UTC 2009, > "url"=>"www.google.com", "id"=>2, "created_at"=>Tue Apr 28 14:48:55 > UTC 2009} > ] > > Nice and smooth. > > But when it is JSON: > > Content.find(:all)[0,2].map(&:attributes) > => [ > {"content"=>#<Content:0x2040d10 @prefix_options={}, @attributes> {"updated_at"=>"2009-04-27T15:04:32Z", "url"=>"www.google.com", > "id"=>1, "created_at"=>"2009-04-27T15:04:32Z"}>}, > {"content"=>#<Content:0x2040248 @prefix_options={}, @attributes> {"updated_at"=>"2009-04-28T14:48:55Z", "url"=>"www.google.com", > "id"=>2, "created_at"=>"2009-04-28T14:48:55Z"}>} > ] > > the problem is that to get an attribute in each Content object I have > to do object.content.url instead of plain content.url. > > Why is this happening? Is there any workaround?