Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails' ActiveRecord serialize :attr method gives "Missing Class or module error"

I'm trying to serialize a simple attribute in an ActiveRecord model, and Rails 2.3.4 doesn't like it.

class Shopper
  serialize :tags
end

>> a = Shopper.new
=> <#Shopper...>

>>a.tags = ['aoeu','stnh']
=> ['aoeu','snth']

>> a.save
=> TypeError: class or module required

anyone know what I'm missing?

like image 685
btelles Avatar asked Oct 06 '09 00:10

btelles


1 Answers

Arf...I thought I could serialize two attributes in one go, but that's not the case:

serialize :tags, :garments   # this is wrong

The second argument is supposed to be the class of the serialized object, so I have to do this:

serialize :tags
serialize :garments

bumsicle.

like image 162
btelles Avatar answered Oct 06 '22 00:10

btelles