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}
  end
end

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

References


Related Articles

Watch this Article as Screencast

You can watch this as a screencast Rails Serialization Basics


Ace the Technical Interview

  • Easily find the gaps in your knowledge
  • Get customized lessons based on where you are
  • Take consistent action everyday
  • Builtin accountability to keep you on track
  • You will solve bigger problems over time
  • Get the job of your dreams

Take the 30 Day Coding Skills Challenge

Gain confidence to attend the interview

No spam ever. Unsubscribe anytime.