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 -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 1/20/07, Adam Block <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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?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 Olson http://weblog.techno-weenie.net http://mephistoblog.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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Reasonably Related Threads
- Question about object permanence/marshalling
- Rails Edge ActiveSupport::TimeWithZone and Marshalled objects
- Symlink shared mailboxes and system_user extra field
- Error with flash and form_authenticity_token in new rails application with scaffolding
- Code coverage for member functions that are defined inside the class