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? Ingo -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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: <product> <id>12345</id> <price>20.99</price> <quantityinstock>500</quantityinstock> </product> This data will be in params[:product][:id] params[:product][:price] params[:product][:quantityinstock] 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. Andrew -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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 this: def create Message.create(params[:product]) end 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.. Ingo -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
This is how I do my create in class ProductsController def create product = Product.new(params[:product]) product.save Are you using Flex or Flash? Andrew -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---