How to deploy your Ruby app to Heroku
This week I decided to try to deploy the backend of an app I created on rails to Heroku.com. Let me tell you, what I thought would be a straightforward process ended up being quite the headache and took a lot of research on stack overflow.
So to give a basic over view of how Heroku works, it is essentially a way of changing the location of your app from localhost3000 to a live web address. The interesting thing that I wish I had known from the start however, is that it functions similarly to git hub in the sense that you can make updates to your “live” production branch from the command line. So in a sense it can be thought of the production branch of your project. Therefore it is a good idea to set up Heroku with your project before you get too deep into development.
It is easy enough to get started. You start by going to heroku.com and creating an account. After doing so the method I recommend is using the CLI commands for heroku to create a heroku remote branch within your git repository. It is as simple as typing in the following:
$ brew tap heroku/brew && brew install heroku
from there you just do
$ heroku create
to create the blank app and you enter
$ git remote -v
this adds the remote heroku app you just created as a place that you can push your git branches to using
$ git push heroku master
This now has your git repo tied to your Heroku app and it should be live but the main reason I wanted to write this blog is because when I did this I continued to get errors for not being in the right version of ruby. It is important to pay attention to this because some versions of ruby are not securely supported by Heroku, and if working with private cookies etc that can be a problem.
So within your command line you can enter rvm list to see what version of ruby you are currently using as well as what you have downloaded. At the time of writing this, Heroku was only supporting Ruby version 2.6.6 and I had made my app in 2.6.1 and had 2.7.0 installed. When I tried changing the ruby version in my gem file and running bundle install it wouldn’t allow me to do so. I was also not allowed to use “rvm install 2.6.6” for some reason. Not really sure what this bug came from but after a lot of reading it actually pointed me to having to update home-brew before updating the RVM and installing it within my gem file. Another reminder to always read errors carefully I suppose.
At any rate, with this hopefully deploying your ruby app is a little easier and happy hacking!