Creating a Rails Backend API from Scratch

rails new sports-api --api -d=postgresql
Lines 8–16 were uncommented, and line 10 was changed to allow access from anywhere.
rails g resource Api::V1::Sport name abbreviationrails g resource Api::V1::League name abbreviation sport:references
the filename and class name were changed by removing api v1
Our updated Sport model
Our updated League model
Our updated file structure for app/models
seeds.rb file with sports and leagues
the index rending json

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store