Step-By-Step Guide to Using Javascript Front-End with a Rails App Backend to Make Your Own API

I was thrown into the fire yesterday. Here’s a checklist so you can cry tears of joy instead of suffering.

Phyllis
2 min readJun 12, 2020

go from this

to this

or even this

without this

  1. create and fill the db/migrate/ migrations rb files that inherit from ActiveRecord::Migration
  2. run rails db:migrate. You will see in the terminal if they were successfully created or if there was an (probably syntax in the create_migration file) error.
  3. confirm the db/schema.rb looks right
  4. create and fill the db/seeds.rb files
  5. run rails db:seed
  6. use rails c or rails console (or database browser software) to confirm the database has been seeded properly.
  7. add appropriate routes in config/routes.rb on the backend
  8. create the app/models model rb files that inherit from ApplicationRecord which inherits from ActiveRecord::Base and designate any relationships
  9. create the matching controllers inheriting from ApplicationController which inherits from ApplicationController:::Base
  10. create and fill app/services/ serializer.rb file for the model
  11. fill in matching controller actions in the corresponding controller.rb in app/controllers/ to pull data from the database and render json: with the data or with plain text string. no need for instance variables because we’re not passing the data to erb views.
  12. run rails s to start up server
  13. confirm at your local server address that the API is rendering data

--

--