Serialize User
Learn to serialize the output of the 'User' model.
The JSON:API Serializer uses the serializer class of Ruby. Serializers are Ruby classes responsible for converting a model into a Hash or a JSON.
Generate serializer for the User
model
To serialize the User
, we need to add a user_serializer.rb
file. We can do it manually,
but the gem provides a command-line interface to do it:
$ rails generate serializer User email
Use this command in the terminal below to add the user_serializer.rb
...