Back to Guides

Attributes

::attributes

Serialization of the resource title and body

In Serializer #attributes
attributes :title, :body { title: 'Some Title', body: 'Some Body' }
attributes :title, :body
def body "Special #{object.body}" end
{ title: 'Some Title', body: 'Special Some Body' }

::attribute

Serialization of the resource title

In Serializer #attributes
attribute :title { title: 'Some Title' }
attribute :title, key: :name { name: 'Some Title' }
attribute :title { 'A Different Title'} { title: 'A Different Title' }
attribute :title
def title 'A Different Title' end
{ title: 'A Different Title' }

PR please for conditional attributes:)

results matching ""

    No results matching ""