# How do I serialize data for a controller action

**URL:** <https://www.ruby-forum.com/t/how-do-i-serialize-data-for-a-controller-action/103645>\
**Category:** Rails\
**Created:** [May 8, 2007, 9:11pm UTC](https://www.ruby-forum.com/t/how-do-i-serialize-data-for-a-controller-action/103645 "2007-05-08T21:11:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmcclean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dmcclean](https://www.ruby-forum.com/u/dmcclean)\
**Post date:** [May 8, 2007, 9:11pm UTC](https://www.ruby-forum.com/t/how-do-i-serialize-data-for-a-controller-action/103645/1 "2007-05-08T21:11:40Z")

</div>

I have two instances of a intranet Rails application running on  
different networks. The database design for each  
is the same, but the data is different.

I occasionally need for certain database records to be copied from  
application to another.  
I would like to serialize the records and send the data to the 2nd  
application’s web server , where  
a controller action would unserialize the records, process them and  
store in the 2nd database.

I am not sure how to do this. Any ideas?

Regards,  
Don Mc

---

<div class="post-metadata">

**Author:** ![dmcclean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dmcclean](https://www.ruby-forum.com/u/dmcclean)\
**Post date:** [May 8, 2007, 11:22pm UTC](https://www.ruby-forum.com/t/how-do-i-serialize-data-for-a-controller-action/103645/2 "2007-05-08T23:22:06Z")

</div>

It sounds like what you might be asking for is marshaling. I haven’t  
tried it, but here’s a reference:  
[Programming Ruby: The Pragmatic Programmer's Guide](http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref_m_marshal.html#Marshal.dump)

–Paul

---

<div class="post-metadata">

**Author:** ![dmcclean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dmcclean](https://www.ruby-forum.com/u/dmcclean)\
**Post date:** [May 9, 2007, 9:30am UTC](https://www.ruby-forum.com/t/how-do-i-serialize-data-for-a-controller-action/103645/3 "2007-05-09T09:30:49Z")

</div>

Or you could follow the hot trend in rails and just have them talk to  
each other via REST.

There’s support in the current version of rails for scaffolding  
(generating) your models as “resources”, which means you get basic  
controller actions that return xml of your object if called as a REST  
call.

ActiveRecord will also do basic serialization to xml out of the box. If  
your needs are fairly straightforward, this can be a very quick thing to  
code.

Oh, and there’s also ActiveResource, a REST client library that allows  
you to use the models from one app in another by making the REST calls  
for you behind the scenes.

And finally, since it’s been a hot topic, there’s lots of information  
out there about RESTful rails…

b

---

<div class="post-metadata">

**Author:** ![dmcclean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dmcclean](https://www.ruby-forum.com/u/dmcclean)\
**Post date:** [May 9, 2007, 4:15pm UTC](https://www.ruby-forum.com/t/how-do-i-serialize-data-for-a-controller-action/103645/4 "2007-05-09T16:15:56Z")

</div>

Paul and Ben,  
Thanks for the help!
