Ruby on Rails Tutorial — Heroku API Deployment


This tutorial requires that you’ve already installed

  • rails
rails new dogs --api -d postgresql

Configuring your Database

Assuming you have a local postgres server make sure you write your database.yml like so. Make sure the username and password matches your local postgres user.

default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
# Make sure the below reflects your local postgres user
port: 5432
host: localhost
username: test5
password: test5
<<: *default
database: mice_development
<<: *default
database: mice_test
<<: *default
url: <%= ENV['DATABASE_URL'] %>
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '*',
headers: :any,
methods: [:get, :post, :put, :patch, :delete, :options, :head]

Create a quick API

Run the following commands for a basic dogs api…

Dog.create(name: "Sparky", age: 5, breed: "Bulldog")
Dog.create(name: "Spot", age: 5, breed: "Dalmation")
Dog.create(name: "Goldy", age: 5, breed: "Golden Retriever")

Test the Api

rails server

Deploy to Heroku

  • push your code to github (make sure the root of the repo is the same folder as the gemfile)
  • create a new heroku project and connect it to your github repo
  • using the heroku cli run the following commands



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
Alex Merced Coder

Alex Merced Coder

Alex Merced is a Developer Advocate for Dremio and host of the Web Dev 101 and Datanation Podcasts.