Class: FieldSerializer
- Inherits:
-
ActiveModel::Serializer
- Object
- ActiveModel::Serializer
- FieldSerializer
- Defined in:
- lib/fields/serializer/field_serializer.rb
Overview
This is a generic serializer intended to return a subset of a model’s attributes. It can be used with any model but does not currently support associations.
Example usage:
`render json: @region, serializer: FieldSerializer, fields: [:id, :title]`
> { "id": "5f19582d-ee28-4e89-9e3a-edc42a8b59e5", "title": "London" }
Instance Method Summary collapse
Instance Method Details
#attributes(*args) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/fields/serializer/field_serializer.rb', line 12 def attributes(*args) adding_id do merging_attributes do args.first.map { |field| create_attribute_structure(field.split("."), object) } end end end |