Deploying to Heroku

As I get closer to finishing up at Flatiron School, I’m starting to think more and more about putting my portfolio together and deploying the apps that we’ve built so far. Since I have quite a bit of work ahead of me to get all of this ready, I’d like to do this as quickly and painless as possible. I’ve been hearing a lot about Heroku, and that it’s easy to use to deploy a rails app, so I decided to research it a little bit, and try it out.

It turns out it is pretty easy to use, and the documentation is great on the Heroku site. There’s just a simple set of steps to follow, to actually deploy a rails app. The beauty of it, is that you can use git to push your app right to Heroku, which makes everything super easy. Here’s the simple set of steps to follow:

  1. Sign up for a Heroku account, then download and install to use the CLI commands, here:
  2. After this you can CD into the directory of your project in your terminal, and run the “Heroku” Login command.
  3. Then run the “Heroku Create” command, which creates a Heroku app to later push the entire app to. You need to specify the name of your app when running this command, for example: Heroku Create Sample-App. This command actually creates a git remote as well called heroku, which allows you to use git to push everything to the app.
  4. Once that’s finished, you can git add, git commit (for any changes that you may have made), and git push heroku master. After this command is run, you should see the new url that it’s assigned for your app.
  5. After pushing the app to Heroku, you’ll need to create and migrate your database, you can do so with the following command: “heroku run rake db:migrate.” You can also take care of seeding your database if you need to as well, with the heroku run rake db:seed command.

After deploying my own rails app, I actually ran into an error when starting up my server. I was getting the error below and didn’t understand where I was going wrong. It turns out, I had individually required a few gems at the top of some controller files in my rails app, which was throwing this error- so I got rid of the “require” to get it to work. (I had required Nokogiri, which is why is specified this in the error).

Once these steps are complete, you can log into your Heroku account and take a look at your dashboard. Here you’ll be able to see your actual server running, and it actually lists out all of the recent activity on the account.There are many other features available as well on the dashboard, including features related to tracking performance for the app. So, as you can see, this was extremely simple, and I was able to get this up and running in a matter of a few minutes, which is excellent.

For this particular app that I deployed, rails was just used for the back-end of the site, so I decided to try and deploy the front-end as well, which was built with Facebook’s React. I actually tried to go through the same steps as above, but it turns out, Heroku doesn’t have built in capability to deploy a React App. In Heroku language, it doesn’t have a native build-pack as it does for Ruby, and some other languages/environments. So I had to search around for an alternative set of steps to make this work. I wound up reading another blog on the Heroku site that explained what to do to incorporate the proper build-pack for a React project- these are the steps that I followed below in order to get it to work:

There’s no need to log into Heroku first, and even if your app is already created and has a git repository, you still need to git init for the new app that’s being created on Geroku. I made the mistake of not following every single one of these steps, and the process wound up being pretty confusing. I the cloned my front-end repository again to start over, and followed these steps in order to get it to work.

ALSO- keep in mind as well that if you’re trying to change the name of an app, you’ll need to change the name of the git remote as well to follow: