diff --git a/CHANGELOG.md b/CHANGELOG.md index 153983704..3b5c57717 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ Fixes: Misc: - [#1673](https://github.com/rails-api/active_model_serializers/pull/1673) Adds "How to" guide on using AMS with POROs (@DrSayre) +- [#1730](https://github.com/rails-api/active_model_serializers/pull/1730) Adds documentation for overriding default serializer based on conditions (@groyoh/@cgmckeever) ### [v0.10.0.rc5 (2016-04-04)](https://github.com/rails-api/active_model_serializers/compare/v0.10.0.rc4...v0.10.0.rc5) diff --git a/docs/general/serializers.md b/docs/general/serializers.md index 664799d0d..875071595 100644 --- a/docs/general/serializers.md +++ b/docs/general/serializers.md @@ -369,3 +369,19 @@ class PostSerializer < ActiveModel::Serializer end end ``` + +## Overriding association serializer lookup + +If you want to define a specific serializer lookup for your associations, you can override +the `ActiveModel::Serializer.serializer_for` method to return a serializer class based on defined conditions. + +```ruby +class MySerializer < ActiveModel::Serializer + def self.serializer_for(model, options) + return SparseAdminSerializer if model.class == 'Admin' + super + end + + # the rest of the serializer +end +```