Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "ostruct"
- class User < ActiveRecord::Base
- serialize :custom
- def after_initialize
- self.custom = OpenStruct.new(custom)
- end
- before_validation :convert_custom_attributes_to_hash
- after_validation :convert_custom_attributes_to_ostruct
- def convert_custom_attributes_to_hash
- self.custom = custom.marshal_dump if custom.kind_of? OpenStruct
- end
- def convert_custom_attributes_to_ostruct
- self.custom = OpenStruct.new(custom) if custom.kind_of? Hash
- end
- end
Add Comment
Please, Sign In to add comment