Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Section A.12. Serialization

A.12. Serialization

Serialization is a module to include in your models when you want to represent your model as a serializable hash. You only need to define an attributes method and the rest is handled for you.

class User
  include ActiveModel::Serialization
  attr_accessor :first_name, :last_name

  def attributes
    { 'first_name' => @first_name, 'last_name' => @last_name }
  end
end


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint