Hi,
I would like to import a serialized object (from a JSON export) inside my database.
It work fine if for instance I do:
l = Yea.create(:title => "foo bar")
=> #<Yea id: 3, title: "foo bar", created_at: "2010-07-05 21:44:54", updated_at: "2010-07-05 21:44:54">
j = l.to_json
=> "{\"yea\":{\"created_at\":\"2010-07-05T21:44:54Z\",\"title\":\"foo bar\",\"updated_at\":\"2010-07-05T21:44:54Z\",\"id\":3}}"
Yea.delete(3)
=> 1
a = ActiveSupport::JSON.decode(j)
=> {"yea"=>{"created_at"=>"2010-07-05T21:44:54Z", "title"=>"foo bar", "updated_at"=>"2010-07-05T21:44:54Z", "id"=>3}}
Yea.create(a.values)
=> [#<Yea id: 4, title: "foo bar", created_at: "2010-07-05 21:44:54", updated_at: "2010-07-05 21:44:54">]
But I think this way is not good, because I would like to write this importation a little bit more generic, for Yea serialized instances or any other one. Is there a way to clean up this with ActiveRecord, for example?
Many thanks.