Rails Serialization Basics

I developed a Electronic Design Automation tool for a startup company using Java Swing in the late 90s. It was a desktop application. Serialization in this context meant when the hardware designer saved their file, the state of the objects was persisted in the file system.

I was confused by the usage of this term in Rails. This term is used to store data in a database column as well as providing data to a JSON api. I came across this blog post Rails ActiveRecord Serialize. I realized I was not alone. I read the Rails documentation for Serialization. I worked through the examples. There was some missing code. Here is the missing class:

class Address
  include ActiveModel::Serializers::JSON

  attr_accessor :city, :state

  def attributes
    {'city' => nil, 'state' => nil}

If you want to contribute to Rails, you can provide this missing code as a patch for the existing documentation.


Related Articles

Watch this Article as Screencast

You can watch this as a screencast Rails Serialization Basics

Create your own user feedback survey