After recently completing a Rails 4 tutorial, I was faced with a frustrating challenge: how the !#$% do I get my new app out in the internet? A former colleague had suggested using Heroku for app hosting while I was in the learning stages. Since the kind of beginner apps I’m creating won’t really take up a lot of space, he said, why bother buying hosting?
An excellent point, but easier said than done. I had built 3/4 of a recipe app on Rails last year, but I was thwarted and eventually gave up when I could not for the life of me figure out how to push my app out on the line. I recently undertook the challenge again though, and finally managed to do it – so for anyone else who needs the beginner’s version to deploying, see below.
1. When using Heroku, you’ll need to change your app’s database from sql to postgres. I am only like 40% sure what that means, but the Heroku docs explain it here (btw, I’m presuming you have already built your app on an sql database. If you’re starting from scratch, you can save yourself considerable time by defaulting your local setup to postgres with the
rails new -d postgresql command.
But, if you’re like me and did not do that, you’ll need to download and install postgres from here. I work in Windows, so I had to download, install and launch the pgAdminIII app, where I made a superuser name and password, as indicated here on Stack Overflow.
2) Go into your Gemfile and, as per Heroku’s instructions, replace
gem 'sqlite3' with
3) Run a bundle install.
4) In your config file (database/config.yml) and change the adapters to
adapter: postgresql. Also, assign unique names to all the databases based on the environment. In my case,
database: db/development.sqlite3 became
5) Something not specified in the Heroku docs that caused me all kind of hassle was creating a username and password for my new postgres database. I struggled with connection errors until I added my username and password to each environment.
It looked something like this:
username: (your superusername)
password: (your password)
Once that’s done, run
$ rake db:create
$ rake db:migrate
You should be all set up now. Just use git to push to Heroku as per the documentation. If you run into problems, feel free to tweet at me and I’ll try to help!