Guides > Serializers

Serializers

Includes any class that has ActiveModel::Serializer as one of its parent classes.

Extending a Base ApplicationSerializer

To share behavior across your serializers you can create an ApplicationSerializer at app/serializers/application_serializer.rb:

class ApplicationSerializer < ActiveModel::Serializer
# Your amazing customizations here
end

Then any newly-generated serializers will automatically descend from ApplicationSerializer.

$ rails g serializer post

Now generates:

class PostSerializer < ApplicationSerializer
  attributes :id
end
`

Generators :link:

Use these to quickly create serializers.

Methods

Serializers can utilize all of the following:

Attributes :link:

Associations :link:

Caching :link:

Scope - Authorization :link:

Adapter Specific :link:

Overriding :link:

What you need to know to customize your serializers.

Examples :link:

Serializing Non-ActiveRecord Objects :link:

Serializer Class on GitHub :link:

results matching ""

    No results matching ""