# Creating Complex ActiveResource objects

**URL:** <https://www.ruby-forum.com/t/creating-complex-activeresource-objects/164881>\
**Category:** Rails\
**Created:** [April 7, 2009, 12:46am UTC](https://www.ruby-forum.com/t/creating-complex-activeresource-objects/164881 "2009-04-07T00:46:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cfranz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ba9def/32.png) [@cfranz](https://www.ruby-forum.com/u/cfranz)\
**Post date:** [April 7, 2009, 12:46am UTC](https://www.ruby-forum.com/t/creating-complex-activeresource-objects/164881/1 "2009-04-07T00:46:02Z")

</div>

Given the following models:

class Uptime \< ActiveRecord::Base  
has\_many :pings  
end

class Ping \< ActiveRecord::Base  
belongs\_to :uptime  
end

I can create an ActiveResource that will get the uptimes and ping  
models:

class UptimeResource \< ActiveResource::Base  
self.site = “[http://localhost:3000](http://localhost:3000)”  
self.element\_name = “uptime”  
end

class PingResource \< UptimeResource  
self.element\_name = “ping”  
end

If the information exists in the database, I can do  
UptimeResource.find(1).pings and get a list of pings. But how can I  
create pings besides creating an UptimeResource and then creating the  
pings separately. I am trying to save the XML into an XML Database and  
bypass a relational database (client requirements). I wish I had  
something like CouchDB\_fu but for XML databases…

Is this a job for DataMapper? I am open to any strategy. Swift kicks  
to the head welcome.

Carl

---

<div class="post-metadata">

**Author:** ![cfranz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ba9def/32.png) [@cfranz](https://www.ruby-forum.com/u/cfranz)\
**Post date:** [April 7, 2009, 10:17am UTC](https://www.ruby-forum.com/t/creating-complex-activeresource-objects/164881/2 "2009-04-07T10:17:16Z")

</div>

Yes you would normally update pings as they occur, unless your  
thinking of submitting  
a xml and doing a bulk update. So the “pinger” is doing a butch of  
pings, then  
sending the results to the backend?  
Then you just need to convert a local array to a xml file and submit  
it to your Restful web app.

---

<div class="post-metadata">

**Author:** ![cfranz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ba9def/32.png) [@cfranz](https://www.ruby-forum.com/u/cfranz)\
**Post date:** [April 7, 2009, 3:07pm UTC](https://www.ruby-forum.com/t/creating-complex-activeresource-objects/164881/3 "2009-04-07T15:07:00Z")

</div>

The “convert a local array to xml” is where I am running into issues.  
I keep trying to set a “pings” property but it isn’t working. How do I  
shove that into the Uptime object so that they are all transmitted at  
the same time?
