From 5c2e61bcfbd5ec7a3883088aaec8a28b29448b0c Mon Sep 17 00:00:00 2001 From: Liz Abinante Date: Tue, 9 Feb 2016 04:08:25 -0800 Subject: [PATCH] [0.8.x] add example for POROs, clear up explanation --- README.md | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d1251a07..d857258c 100644 --- a/README.md +++ b/README.md @@ -45,18 +45,35 @@ the serializer generator: $ rails g serializer post ``` -### Support for PORO's and other ORM's. +### Support for POROs and other ORMs. Currently `ActiveModel::Serializers` adds serialization support to all models -that descend from `ActiveRecord` or include `Mongoid::Document`. If you are -using another ORM, or if you are using objects that are `ActiveModel` -compliant but do not descend from `ActiveRecord` or include -`Mongoid::Document`, you must add an include statement for -`ActiveModel::SerializerSupport` to make models serializable. If you -also want to make collections serializable, you should include +that descend from `ActiveRecord` or include `Mongoid::Document`. If you are: + +- using another ORM, or +- using objects that are `ActiveModel` compliant but do not descend from +`ActiveRecord` *or* include `Mongoid::Document` + +You must add an include statement for `ActiveModel::SerializerSupport` to +make models serializable. + +If you also want to make collections serializable, you should include `ActiveModel::ArraySerializerSupport` into your ORM's relation/criteria class. +Example model (`app/models/avatar.rb`): + +```ruby +class Avatar + include ActiveModel::SerializerSupport + # etc, etc +end +``` + +If your classes follow the naming conventions prescribed by `ActiveModel`, +you don't need to do anything different in your controller to render the +serialized json. + # ActiveModel::Serializer All new serializers descend from ActiveModel::Serializer