rails xml to active record object

Posted by Brian D. on Stack Overflow See other posts from Stack Overflow or by Brian D.
Published on 2010-05-10T20:57:17Z Indexed on 2010/05/10 22:34 UTC
Read the original article Hit count: 247

I've been googling for a while to try and convert and incoming XML request into an active record object. I've tried using the ActiveRecordObject.new.from_xml method but it doesn't seem to handle relationships.

For example, say I have the following xml:

<blog>
  <title></title>
  <blog-pages>
    <blog-page>
      <page-number></page-number>
      <content></content>
    </blog-page>
  </blog-pages>
</blog>

And I have the following model objects:

class Blog < ActiveRecord::Base
    has_many :blog_pages

end

class BlogPage < ActiveRecord::Base
    belongs_to :blog

end

Is there a way to convert the xml into a blog object WITH relationships? Or do I need to manually parse the XML?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about activerecord