FindFurryFriend (part 3) — rails api (controllers and serializers)

Meghan Elizabeth
2 min readMay 25, 2021
Photo by Pauline Loroy on Unsplash

Controllers

The controllers are the logical part of your application. They are Ruby classes which inherit from ApplicationController and contain methods. After a HTTP request goes through the routing process and has determined which controller to use for the request, the controller is responsible for performing the logical part of the request and producing the appropriate output.

Strong params

Strong Parameters are located in the controller. They are a security feature of rails that prevents unwanted data from entering our database. This is helpful because it protects our database by only allowing a user to submit data that we explicitly permitted into our database.

Serializers

Serializers are ruby gems that allow us to format our JSON data in a more organized way. In order to setup we need:

  1. Add to gem file and run ‘bundle install’
  2. Setup serializer files by running ‘rails g serializer shelter’ and ‘rails g serializer pet’
  3. Edit each files association info and attributes
  4. Make sure each controller action that needs to view json data has the appropriate serializer (ex. shown above in controller images- render json: @shelter) in order to render json

Happy coding ✌️

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response