How To Deploy A Rails API To Heroku

I recently created and deployed an application called Tip Out. It’s an application that enables waiters and waitresses the ability to record and view tip outs. My inspiration came from my current employer, MadLife Stage & Studio, where I currently work as a waiter. The application was built with Ruby on Rails and PostGres in the back end, and React, JavaScript, HTML, and CSS in the front end. After completing the first version of my application over the course of 3 weeks, it was time to deploy Tip Out. While trying to deploy my back end, I realized I had forgotten how to deploy a Rails API to Heroku. After diligent research, I rediscovered how to do it. I would now like to share 7, possibly 8 easy steps for deploying a Rails API to Heroku.

The first step is to switch the database from SQL to Postgres. Locate the Gemfile and replace the following…

gem 'sqlite3'

with the following…

gem 'pg'

Then run bundle install! Next we need to update the database.yml file before moving onto step 2. Locate the database.yml file in the config folder. Your config/database.yml file should look like this…

but you will replace it with the following…


That is it for step 1!

Open the terminal on your Rails API project. Type in the following command in the terminal to log in to your Herkou account.

heroku login

You should be prompted with a message to press any key to proceed.

Press any key and a browser window should open with a button to log in.

Please ensure you have a Heroku account before continuing with this article!

After selecting log in, your terminal should now display a message stating who heroku is currently logged in as.

Time to create the Heroku app from the terminal. Use the following command to create a Heroku app.

heroku create app-name

Use the following command to add all of the project for an update push.

git add .

Use the following command to add a message associated with the push update. This allows yourself and other developers to know the reasoning for the last update or what it consisted of.

git commit -m'first deploy'

Time to push the project to Heroku. Use the following command to do so.

git push heroku master

Use the following command to migrate the database on Heroku. This is very important! Please don’t forget this step! This is the last step if no seeding if necessary!

heroku run rake db:migrate

If you have a seeds.rb file with data in your Rails API, please use the following command to seed the database on Heroku. This is the last step!

heroku run rake db:seed

You should now be able to access your database in the browser by accessing the correct route end points associated with your new Heroku app web address! I forgot how easy it was to complete the process. If I ever forget how to do deploy a Rails API to Heroku again, I can now reference this article, and you can too!

I hope you found this article helpful, and please feel free to reach out to me. You can connect with me on LinkedIn or check out my portfolio site! Thanks for reading, and I hope you have a great day!

Full Stack Software Engineer