Search code examples
ruby-on-railsjsonfacebookkoala

Storing json (facebook api) in database & retrieve them


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 ?


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