views:

177

answers:

2

I want to save a set of email addresses collected from a text field (separated by commas) into a single field in a table. I am trying to use serialize but I'm getting SerializationTypeMismatch error. How can I do this?

This is my model:

class Crew < ActiveRecord::Base

class Recipients < HashWithIndifferentAccess ; end

serialize :recipients, Recipients

end

+2  A: 

I would really reccomend that you parse (e.g. split on comma) the email list and put each in a row in a separate table (I assume you're talkin about a database table?). If you want to use the email addresses for something it's better to store them individually, and since you're talking about serialization I guess you've allready parsed the emails, and try to store an array or similar into a single field in a database. The "correct" normalized database way of doing this is to in your model wich you're currently trying to save the object, add a has_many :emails (or similar) and creat a new email table for each email.

One should allways have a very good reason for storing list type data in a blob, instead of using a proper associated table.

Stein G. Strindhaug
+1  A: 

If you are given a comma separated list of email addresses, and if when you need to use that information, a comma separated list is useful, then just put it in a text column in your model, without serialization.

If you need to serialize the list, wouldn't it be an array? Can you explain the choice of a hash?

Michael Gee