Sending Better Data With Rails Serializers - DEV Community
05-May-2023 551
Using Ruby on Rails as an API is awesome because of its render :json method. The only problem is that many times the JSON data may contain many unnecessary things. We want more options to customize the data and we can do that using serializers. We can use serializers to format our JSON by selecting only the data that we really need as well as get access to model relationships. Let’s get started.In this example we can imagine that you want to query a list of Pokemon and their trainer from your database. Let’s create two models.
Sending Better Data With Rails Serializers - DEV Community #ruby #rubydeveloper #rubyonrails #Sending #Better #Rails #Serializers #Community #dev https://rubyonrails.ba/link/sending-better-data-with-rails-serializers-dev-community