Skip to content

0.8: specifying custom attribute type does not work  #1738

Open
@bughit

Description

@bughit

In the following docs example :string turns into a key in the serialized hash
Specifying the type is seemingly pointless even if it worked, what's it for?


The type of a computed attribute (like :full_name above) is not easily calculated without some sophisticated static code analysis. To specify the type of a computed attribute:

class PersonSerializer < ActiveModel::Serializer
  attributes :first_name, :last_name, {:full_name => :string}

  def full_name
    "#{object.first_name} #{object.last_name}"
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions