Custom Serializers in Ruby on Rails

Tram Ho

New coders are often surprised when entering new projects that have new technologies, find people to use it very easily, and I struggle to find out. And my difficulty encountered is ActiveModel Serializers. After researching and using, I see Serializers as a magic hand to help data taken from active records, I can manipulate it to fit the data I need. Quite interesting, and useful especially for projects using the Rails API to manipulate Json type data. So this article I want to share for new friends as I can approach the easiest way to understand it as well as initially be able to use and customize the data accordingly.

1. Demo data

Model Relationships

And here is the content of their model:


We will start with the Index and Show actions in Restful and they are almost the same:
Share the news now

Source : Viblo