How to deploy a RailsAPI to Heroku

Kody Samaroo
2 min readAug 22, 2021

Introduction

Deploying to Heroku is relative simple and the guide on the website is very accurate and concise. This blog post will restate a lot of the stuff in that guide. The purpose of this post is really to outline the process with a Rails API and try to go over some problems you may run into and ways to troubleshoot them.

Here is a link to the Heroku setup: https://devcenter.heroku.com/articles/getting-started-with-rails6

If you followed my last blog and created a Real-time Messaging Application you can use this guide to deploy that project.

Heroku CLI

The very first step should be to make an account on Heroku. One you have an account setup we will login using the following command

Heroku login

Press any key to go to the login page in the browser. You will have to enter your login credentials. You terminal will update with a successful login by showing you the email you have have signed into.

Now that we are logged in, cd into the root directory of the project. Note that will we need to have initialized a git repository. If you have never done that before it can be difficult but GitHub walks you through the process and it is pretty straightforward.

Heroku create

The next step will be to create the Heroku deployment this is sort of like initializing a GitHub repository. In order to create a Heroku deployment we run the following command

Heroku create

Then we simply run

Heroku git push <branch>

Now your Heroku deployment will build and once it is finished we will have a domain for our API. Everywhere in the frontend of our application that we use the locahost domain can be substituted with the new Heroku domain.

If you go to your Heroku dashboard you can see the domain and other details about the app. The most important of which especially for troubleshooting are the view logs.

More > View logs

--

--