Pulling Out the Representation Layer
This chapter finishes the journey of reducing Active Record models’ responsibility by discussing representation-specific logic, which we sometimes put into our model classes. First, we will consider view-template-related helpers and how we can extract them into decorating objects or presenters. Then, we will discuss the concept of serialization in API-only applications and how we can organize the corresponding logic using serializers.
We will cover the following topics:
- Using presenters to decouple models from views
- Serializers are presenters for your API
The aim of this chapter is to show you how to extract representation-related logic from models to eliminate the coupling introduced by mixing presentation and domain logic in the same architectural layer. By doing so, we will keep our code base maintainable.