Reputation: 111090
I'm looking to learn how to serialize data in Rails 3...
Things I'd like to learn:
Thanks!
Upvotes: 10
Views: 22161
Reputation: 35042
ActiveRecord has this build in: http://api.rubyonrails.org/classes/ActiveRecord/Base.html#method-c-serialize
If you specify in your model that an attribute is serialized, then AR transparently handles the serialization/deserialization. When you call the accessor, it'll deserialize on the fly return the Ruby object (hash, array, whatever). Then you can modify the object as you would normally, and when you save the record, it'll re-serialize and store it.
Upvotes: 21