I have a model foo with two fields: id and string. When I try to save a
symbol into that string field I get weird results:
foo = Foo.new(:string => :foobar)
foo.string
=> :foobar
foo.save
foo.string
=> :foobar
foo = Foo.find(foo.id)
=> #<Foo:0x467282c @attributes={“id”=>5, “string”=>"— :foobar\n"}>
foo.string
=> “— :foobar\n”
Apparently the database save is converting the symbol into YAML. But I
don’t know why and I can’t seem to unmarshal it. Any idea what’s going
on?
Thanks!
/adam
On 1/20/07, Adam B. [email protected] wrote:
foo = Foo.find(foo.id)
=> #<Foo:0x467282c @attributes={“id”=>5, “string”=>“— :foobar\n”}>
foo.string
=> “— :foobar\n”
Apparently the database save is converting the symbol into YAML. But I
don’t know why and I can’t seem to unmarshal it. Any idea what’s going
on?
Yea, it serializes non-db fields to yaml. Use the serialize method to
unserialize it for you.
http://rails.rubyonrails.org/classes/ActiveRecord/Base.html#M001004
–
Rick O.
http://weblog.techno-weenie.net
http://mephistoblog.com