Serialize still does not working in Rails 2.1.1 so I’ve created a quick workaround.
I have a database field serialized where I want to store some values set by checkboxes on the UI.
When there are no checkboxes checked Rails serializes this data by default to “0″. On de-serializing Rails will run itself into an error message.
My workaround is to catch in the controller’s create/update actions the empty checkboxes scenario and replace with a correct value which will be never used in my application.
For example, if I’m always storing in the serialized field values from 1..10 i’ll use the <empty> value as a workaround.
In the model:
1 2 3 | class ModelName < ActiveRecord::Base serialize :days ... |
In the controller:
1 2 | # patch for serializing a nil param params[:period][:days] ||= ["<empty>"] |


