How can I serialize and communicate ActiveRecord instances across identical Rails apps?

Posted by Blaine LaFreniere on Stack Overflow See other posts from Stack Overflow or by Blaine LaFreniere
Published on 2010-02-20T18:24:58Z Indexed on 2010/03/15 18:39 UTC
Read the original article Hit count: 386

Filed under:
|
|
|

The main idea is that I have several worker instances of a Rails app, and then a main aggregate

I want to do something like this with the following pseudo pseudo-code

posts = Post.all.to_json( :include => { :comments => { :include => :blah } })
# send data to another, identical, exactly the same Rails app

# ...
# Fast forward to the separate but identical Rails app:
# ...

# remote_posts is the posts results from the first Rails app
posts = JSON.parse(remote_posts)  
posts.each do |post|
  p = Post.new
  p = post
  p.save
end

I'm shying away from Active Resource because I have thousands of records to create, which would mean thousands of requests for each record. Unless there is a way to do it all in one request with Active Resource that is simple, I'd like to avoid it.

  • Format doesn't matter. Whatever makes it convenient.
  • The IDs don't need to be sent, because the other app will just be creating records and assigning new IDs in the "aggregate" system.
  • The hierarchy would need to be preserved (E.g. "Hey other Rails app, I have genres, and each genre has an artist, and each artist has an album, and each album has songs" etc.)

© Stack Overflow or respective owner

Related posts about serialization

Related posts about JSON