XML to model conversion

Hi all,

I know I can use ‘to_xml’ to get an xml representation of a model.
However, is there an easy built-in way to convert xml(for example coming
in as a REST web service call) back to a model? Or do I need to write my
own method for parsing it using REXML?


I hope this makes sense. I am quite new to Rails, but have got my test
app working where the ‘input’ to a model Create or update is an XML
string. This XML only contains data relevant for the model, it is not a
web service.

The data magically appears in the params variable.

So if the xml looks like:


This data will be in

The slight annoyance is accessing id for the model so I do
params[:id] = params[:product][:id]

This works for me and I use it to do updates, and create. If there is a
better way, I’d like to know?

I don’t know if this is what you are looking for.


Thanks, Andrew!

I tried this, but it doesn’t seem to work for me. When my model XML is
POSTed, what you suggested let me expect to be able to do something like

def create

But that doesn’t work. The POST comes from a Flash XML class - maybe I
need to look into exactly how Flash sends the request…


This is how I do my create
in class ProductsController

def create
product = Product.new(params[:product])

Are you using Flex or Flash?


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs