Reconstructing ActiveRecord from YAML

hello, please give me snipped, that reconstruct ActiveRecord object from
YAML or Marshal.dump. When i type for example: YAML::load(item.to_yaml),
the returned object is not (item’s class) Item. When i use:
Marshal::load(Marshal::dump item), it throws exception “undefined
class/module Item” How can I do this? Thanx.

Frantisek P. wrote:

hello, please give me snipped, that reconstruct ActiveRecord object from
YAML or Marshal.dump. When i type for example: YAML::load(item.to_yaml),
the returned object is not (item’s class) Item. When i use:
Marshal::load(Marshal::dump item), it throws exception “undefined
class/module Item” How can I do this? Thanx.

At a guess, a model’s attributes member is very Hash-like, and Hashes
are also a native YAML type. So you might store it with yaml_string
= model.attributes.to_yaml , and load that with model.attributes =
YAML::load(yaml_string).


Phlip
http://c2.com/cgi/wiki?ZeekLand ← NOT a blog!!