Forum: Ruby on Rails Different behaviour on ActiveResorce with JSON or XML

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Paulo P. (Guest)
on 2009-04-29 16:00
(Received via mailing list)
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 P. (Guest)
on 2009-04-30 20:56
(Received via mailing list)
Should it be better to post in the Rails Lighthouse?
This topic is locked and can not be replied to.