Click here to share this article on LinkedIn »

After hours of coding, tweaking, and editing, you finally have a rails web application you’re proud of. Good job! Now, how do we share that with the world? I’ll quickly demonstrate how to set up your rails project online using a FREE Heroku account, and what bumps you may encounter when deploying.

First off, let’s start with your app. Mine is Stylpfizer, closet to the stars 🌟:

Stylpfizer on my local server

In order to deploy to Heroku, you need to have an account with them. If you don’t have one already, click here to sign up.

Now, Heroku has their instructions to deploy a rails app here. I found the instructions to be pretty clear, and it may be all you need. However, if you want a more in-depth version of the documentation, as well as solutions to some of the problems I faced, read on:

1. Heroku toolbelt, Git, & Ruby/Rails versions

Before you can deploy to Heroku, you need to have installed the Heroku toolbelt, as well as have your app in Git, which is a distributed control management tool, and the right version of Ruby and Rails.

What I did was deploy my project to a Github repository, which then allowed me to share my code and view the edits that I made. If you have no idea what I’m talking about, you can sign up here for a FREE Github account. You also need to push up your rails app to a repository in Github, like it says in the documentation. If everything’s hooked up correctly, you’ll see (master) and the name of your repository in the terminal, like shown below.

Lastly, the Ruby you’re using should be version 2.2.0 or above, and Rails should be version 5 or above. To check which one you have, simply type out ruby -v and rails -v in the terminal, like so:

These are the versions I’m using in my module-two-project repository

1A. Switch SQLite with PostgreSQL

When creating your rails application, the default is to work with SQLite for your database. The problem is that Heroku applications work better with the PostgreSQL database system, so we’re going to have to fix this before we deploy to Heroku. If you don’t do this, your rails app database will be emptied at least once every 24 hours. This happens due to the way SQLite stores memory in files on a disk, which Heroku’s Cedar stack clears periodically. More information about the why you shouldn’t use SQLite can be found on their website.

In order to change database systems, we have to first replace the ‘sqlite3’ gem with the ‘pg’ gem in the Gemfile:

Changed the ‘sqlite3’ gem with the ‘pg’ gem

***IMPORTANT SIDENOTE***

I encountered a problem with the pg gem. At the moment of writing this blogpost, it seems like the newest version of the PostgreSQL gem (1.0.0) doesn’t work well with the latest version of Rails. This is the error that kept coming up:

Error with pg gem 1.0.0

A way to work around this is using an earlier version of the gem. You can specify that in the Gemfile like so: