# ActiveResource with a Database?

**URL:** <https://www.ruby-forum.com/t/activeresource-with-a-database/182030>\
**Category:** Rails\
**Created:** [January 21, 2010, 8:19pm UTC](https://www.ruby-forum.com/t/activeresource-with-a-database/182030 "2010-01-21T20:19:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidstokar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@davidstokar](https://www.ruby-forum.com/u/davidstokar)\
**Post date:** [January 21, 2010, 8:19pm UTC](https://www.ruby-forum.com/t/activeresource-with-a-database/182030/1 "2010-01-21T20:19:38Z")

</div>

To start off, I don’t know if this is unorthodox, or if someone has had  
to implement something similar. I’ve searched all over Google and don’t  
really a see a good solution for what I’m trying to do.

Basically I created my own plugin that subclasses ActiveResource so that  
I can consume non-REST URIs and get back XML. That’s easy, there are  
lots of exmaples online of how to do that. Basically, I then use a gem  
called happymapper to bind the XML to Ruby objects. Again, this works  
very easily as well. Now here’s where I’m stuck. I want to persist the  
Ruby object to a local database so that I don’t have to go out and get  
it again. I had a thought of using the save method from ActiveRecord  
since all the DB plumbing is built in, but I’m a little bit at a loss as  
to how I can call ActiveRecords’s save method from a subclass of  
ActiveResource as Ruby doesn’t allow multiple inheritance.

Has anyone else needed to use ActiveResource to extract data, and then  
come up with a method to persist that data to a local DB? Using the  
ActiveResource save method will attempt to POST it back to the place  
where I got it, and it’s a read-only resource.

Thanks for your help everyone!

David

---

<div class="post-metadata">

**Author:** ![davidstokar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@davidstokar](https://www.ruby-forum.com/u/davidstokar)\
**Post date:** [January 22, 2010, 6:20pm UTC](https://www.ruby-forum.com/t/activeresource-with-a-database/182030/2 "2010-01-22T18:20:42Z")

</div>

On Jan 21, 2:19 pm, David Sainte-claire [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> it again. I had a thought of using the save method from ActiveRecord  
> since all the DB plumbing is built in, but I’m a little bit at a loss as  
> to how I can call ActiveRecords’s save method from a subclass of  
> ActiveResource as Ruby doesn’t allow multiple inheritance.
> 
> Has anyone else needed to use ActiveResource to extract data, and then  
> come up with a method to persist that data to a local DB? Using the  
> ActiveResource save method will attempt to POST it back to the place  
> where I got it, and it’s a read-only resource.

Depending on the object, serializing (either to YAML or Marshal  
format) might work. Then you’d just store the whole serialized object  
(now basically a BLOB) to the DB.

Not sure how well ActiveResource plays with serialization, but it’s  
worth a try.

–Matt J.
