Question

I've been storing some data from facebook api using koala gem in database :

fb_data = graph.get_connections(...)
fb_data.each do |t|
    obj.raw_data = t
    obj.save
end

and it looks like that when I extract it from database :

--- id: '111222333444' from: name: James B id: '44444333332222' story: XXX ...

It's not a format I familiar with, thus I was wondering if I did something wrong ?

Was it helpful?

Solution

So here is the answer, I found with the help of @miguelgraz :

fb_data = graph.get_connections(...)
fb_data.each do |t|
    obj.raw_data = YAML::dump(t) #Serialize the hash
    obj.save
end

and then, to retrieve data :

t = YAML::load(t) #deserialize it

OTHER TIPS

You're probably saving it in its raw format indeed, try using something like t.to_json to save a json of this info, maybe something like

fb_data = graph.get_connections(...)
fb_data.each do |t|
  obj.raw_data = t.to_json
  obj.save
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top