Create object from XML string in Ruby
-
05-07-2019 - |
Question
I am trying to deserialize an object from XML in Ruby.
Something simple like:
u = User.new({:client_key => "Bar"})
v = User.new(u.to_xml)
I get an error:
NoMethodError: undefined method 'stringify_keys!' for #String:0x20fc7cc>
I'm not sure what I have to do in order to get the string from XML to an object.
Update: @avdi gave me the tip. I was expecting from_xml to be a self method. You have to create the object first.
v = User.new
v.from_xml(s)
Solution
A quick search turns up http://api.rubyonrails.org/classes/ActiveRecord/Serialization.html#M001420
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow