From: Jan Svitok Date: 2006-10-07T03:26:23+09:00 Subject: Re: active record question On 10/6/06, Dark Ambient wrote: > Sorry guys, I try and keep these sorts of questions to the Rails list but > I've had little luck over there. Since this is a Ruby / Active Record > question I thought I'd throw it out here. > Apologies if it's not appropriate. > > Basically I have a form for the user to fill in. Within it are various > select lists and those are set to multiple, so user can make multiple > choices. > I seem to be able to get them into the database using serialize() , but > integers appear particularly funky with lots of hyphens and quotes. As well > these values will be needed for queries and my understanding is that > serialize is not the way to go. > > So I wouldn't mind some recommendations regarding options I might have to > accomplish this feat, not including (more tables, if that's possible). > My initial thoughts and I haven't tried it yet is perhaps using some type of > regex to clean them up marshalling out , but not entirely sure if that makes > sense. I suppose you can clean up the serialized form via custom attribute setters, getters (AWDwR page 284:) class ProductData < ActiveRecord::Base CU = 18 def length read_attribute("length") * CU end def lenght=(inches) write_attribute("length", Float(inches) / CU) end end Then it depends on what form is convenient for you and that depends on the data type and what you plan to do with the data (for example you could do array.map {|i| i.to_s}.join(',') for an array of integers) Disclaimer: not tested, pure theory ;-) J.