Rails Girls - Pushing to Heroku on Cloud 9

Created by Sorcha Abel, @sabel25

Getting started

Deploying to Heroku on Cloud 9 is easy! All you need is a Heroku Account. If you don’t already have you sign up here -> sign up page Then all you need is to remember your username and password :)

Updating our database

Return to Cloud9 and open the Gemfile We need to make a small change in order to get our database to work on Heroku. It uses a database called PostgreSQL which is more suited to a production environment than SQLite which is the database we have been using so far. Please change the following in the Gemfile:

gem 'sqlite3'

to

group :development do
  gem 'sqlite3'
end
group :production do
  gem 'pg'
end

Here we are telling our app that when in production environment use PostgreSQL (that’s the pg bit) and when in a development environment use the SQLite database. Clever huh!

Finally save the Gemfile and run bundle install --without production to setup your dependencies.

Commit your changes to github

git add Gemfile
git add Gemfile.lock
git commit -m 'updating Gemfile for prep push to heroku'
git push origin master

Deploying your app

App creation

You first need to login to Heroku, type heroku login and enter your heroku username and password

To ensure we are using the most up to date version of Heroku enter the following command in the terminal window of Cloud 9 wget -O- https://toolbelt.heroku.com/install-ubuntu.sh | sh

Next we need to create our Heroku app by typing heroku create in the cloud 9 terminal and see something like this:

sorcha:~/workspace (master) $ heroku create
Creating app... done, ⬢ murmuring-bayou-70721Git remote heroku added

In this case “murmuring-bayou-70721” is your app name.

Pushing the code

Next we need to push our code to heroku by typing git push heroku master. You’ll see push output like the following:

Initializing repository, done.
Counting objects: 101, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (91/91), done.
Writing objects: 100% (101/101), 22.68 KiB | 0 bytes/s, done.
Total 101 (delta 6), reused 0 (delta 0)

-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.0.0
-----> Installing dependencies using 1.6.3
       Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
       Fetching gem metadata from https://rubygems.org/..........
...
-----> Launching... done, v6
       http://sheltered-refuge-6377.herokuapp.com/ deployed to Heroku

You’ll know the app is done being pushed, when you see the “Launching…” text like above.

Migrate database

Next we need to migrate our database like we did locally during the workshop: heroku run rake db:migrate.

When that command is finished being run, you can hit the app based on the url. For this example app, you can go to http://sheltered-refuge-6377.herokuapp.com/. You can also type heroku open in the terminal to visit the page.

Keep in touch

Follow us on twitter

Sorcha

Rachelle

Rails Girls Brisbane

Read the Rails Girls Brisbane blog http://railsgirlsbne.com/

Email us: Rails Girls Brisbane

Join our Facebook Group: Rails Girls BNE Group