Ruby on Rails

Active Model Serializers

Introduction#

ActiveModelSerializers, or AMS for short, bring ‘convention over configuration’ to your JSON generation. ActiveModelSerializers work through two components: serializers and adapters. Serializers describe which attributes and relationships should be serialized. Adapters describe how attributes and relationships should be serialized.

Using a serializer

class SomeSerializer < ActiveModel::Serializer
  attribute :title, key: :name
  attributes :body
end

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow