0.02
No commit activity in last 3 years
No release in over 3 years
Rails attribute serialization into yaml, json, xml and with ruby marshal.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0

Runtime

>= 0
>= 3.0.0
 Project Readme

Serialize for Rails¶ ↑

Rails 4 note¶ ↑

There were some internal changes in Rails 4 regarding the serialize method. These changes seem to affect how serialize works in combination with binary column types such as bytea. For the moment I do not recommend using binary column types in combination with this gem on Rails 4. If you want to know more see github.com/rails/rails/issues/10830#issuecomment-18883754

Description and use¶ ↑

Rails already supports serialization of attributes, but it can only do Yaml. This gem upgrades the default Rails serialize method so you can serialize into yaml, json and with marshal (Ruby binary format). It also supports gzipping the output if you want it to take up less space.

Format can be one of the following:

:yaml, :json, :marshal

Yaml is the default, and serialize will behave just like normal if you don’t use any of the new options.

Example usage:

class Mouse < ActiveRecord::Base
  serialize :info, Hash, :format => :json
  serialize :data, :format => :yaml, :gzip => true
end

When you use gzip you must use a binary-compatible column type such as ‘BLOB` (MySQL) or `bytea` (PostgreSQL). If you don’t use gzip, ‘text` is recommended to allow strings of arbitrary length.