I have an item which has a hash for one of its fields. When i store it in the db, i want to do a Marshal.dump of the hash, and similarly, do a Marshal.load to turn the saved blob back into a hash again. Is there a way to easily write this into the model, so that it happens automatically when saving and loading a record? thanks max -- 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 Nov 6, 2007 9:01 AM, Max Williams <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I have an item which has a hash for one of its fields. When i store it > in the db, i want to do a Marshal.dump of the hash, and similarly, do a > Marshal.load to turn the saved blob back into a hash again. > > Is there a way to easily write this into the model, so that it happens > automatically when saving and loading a record? > > thanks > maxCheck out ActiveRecord::Base.serialize http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M001020 class Foo < ActiveRecord::Base serialize :bar end HTH, Michael Guterl --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Michael Guterl wrote:> Check out ActiveRecord::Base.serialize > > http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M001020 > > class Foo < ActiveRecord::Base > serialize :bar > end > > HTH, > Michael GuterlYeah, i just discovered that as well, it''s exactly what i was after, cheers! -- 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 -~----------~----~----~----~------~----~------~--~---