Forum: Ruby on Rails ActiveResource with Json

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.
Steve D. (Guest)
on 2009-01-27 00:50
Hi all.  I'm hoping maybe someone can help me out.

I recently switched from using xml to json in my ARe models.  I was
excited to see that in irb I was seeing dramatic improvements in
speed.  However, when I fired up the app in my browser I got an error
on a local db find based upon an id i had intended to receive through an
ARe record.  I opened irb again to investigate:

object = AResource.find(461).id

the ARe record is found, however the id attribute returns as nil,
where as, when I was using xml, I had no problems with it.

(the reaons i'm doing the find(id).id is to demonstrate that the
record returned does not have the id which i used to search for the
record.  All other attributes are present, however, the object is also
showing new_record=true, which i'm supposing is the reason it has a
nil id)

Any thoughts on what I can do maintain that id?  The only thing I can
come up with is that i have a local model name that is the same as the
object class that is returned from the remote application, though, like
I
said, there was no problem when using xml.

The following is from irb (object1 is the xml request and object2 is
the json request--both point to the same resource)


Code :

>> object1 = MMTest.find(1)
=> #<MMTest:0x4058328 @prefix_options={}, @attributes={"name"=>"Visa",
"updated_at"=>nil, "id"=>1, "status"=>1}>

>> object2 = MMCreditcardType.find(1)
=> #<MMCreditcardType:0x404c4c4 @prefix_options={}, @attributes=
{"creditcard_type"=>#<CreditcardType id: nil, name: "Visa", status:
true, created_at: nil, updated_at: nil>}>

Thanks in advance,

~Steve
This topic is locked and can not be replied to.