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.
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to