Hey,

I'm writing an application that stores models attributes in a single  
column called `data`, using Marshal. My ultimate goal is to allow any/ 
all records to be saved in one database table. I'm wondering if  
there's a better way to do this, and also if I should Base64 encode  
the result of Marshal.dump as mentioned here: 
http://www.ruby-forum.com/topic/164786#723805

Here's my current code:

# Post(id: integer, data: text, type: string, created_at: datetime,  
updated_at: datetime)
class Content < ActiveRecord::Base
   private
     def unmarshal
       Marshal.load(self.data)
     end
end

class Post < Content
   before_save :marshal

   def title
     unmarshal[:title]
   end

   def title=(value)
     @title = value
   end

   private
     def marshal
       self.data = Marshal.dump({ :title => self.title })
     end
end

Thanks for any tips/help!



--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to