Assume that you have rest url “http://localhost:3000” that return as xml as below:

Output from http://localhost:300


<tests type="array">
<test>
<created-at type="datetime">2009-03-19T08:47:57Z</created-at>
<id type="integer">1</id>
<name>my lab</name>
<sex>M</sex>
<updated-at type="datetime">2009-03-25T01:59:10Z</updated-at>
</test>
<test>
<created-at type="datetime">2009-03-24T08:15:14Z</created-at>
<id type="integer">2</id>
<name>jack</name>
<sex>M</sex>
<updated-at type="datetime">2009-03-24T08:15:14Z</updated-at>
</test>
</tests>

Code example

First you need to create one class called Test:

require 'rubygems'

require 'activeresource'

class Test < ActiveResource::Base

self.site = "http://localhost:3000"

end
&#91;/sourcecode&#93;

<em>
</em>

<strong>And now we call the created Test class</strong>:

T = Test.find(1)

Note: Class Name and XML tag name must be the same without case sensitive.



Advertisements