Using rails (4), I would like to parse some data from an external API and store it into my database. For instance:
{ "name" : "Mercedes-Benz",
"commonName: "Mercedes",
"vehicles" : [ {
"name" : "Mercedes c5",
"components" : ["wheels", "doors"]
}]
}
I am aware that with JSON.parse
I could create a new instance and store it if the json would match, but there are a few problems that prevent me to do it:
commonName
uses cammelcase instead of rails typical underscore. Is there a way i can magically assign a key to an attribute?Will
vehicles
be saved to the tablevehicles
? Can I accomplish that automatically? Or should I go through every vehicle and save each one?Components is just an array of strings. What would be a good way to represent that? Just another table with an attribute
name
?