Put Your App Online With Heroku
Created by Terence Lee, @hone02
Follow steps 1 through 3 of the quickstart guide to sign up, install the toolbelt, and login.
COACH: Talk about the benefits of deploying to Heroku vs traditional servers.
Preparing your app
Updating our database
First, we need to get our database to work on Heroku, which uses a different database. Please change the following in the Gemfile:
group :development do gem 'sqlite3' end group :production do gem 'pg' end
bundle install --without production to setup your dependencies.
COACH: You can talk about RDBMS and the different ones out there.
Version Control Systems
We need to add our code to version control. You can do this by running the following in the terminal:
git init git add . git commit -m "initial commit"
COACH: This would be a good time to talk about version control systems and git.
Deploying your app
We need to create our heroku app by typing
heroku create --stack cedar in the terminal and see something like this:
Creating evening-sky-7498... done, stack is cedar http://evening-sky-7498.herokuapp.com/ | email@example.com:evening-sky-7498.git Git remote heroku added
In this case “evening-sky-7498” 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:
Counting objects: 134, done. Delta compression using up to 4 threads. Compressing objects: 100% (115/115), done. Writing objects: 100% (134/134), 35.29 KiB, done. Total 134 (delta 26), reused 0 (delta 0) -----> Heroku receiving push -----> Ruby/Rails app detected -----> Installing dependencies using Bundler version 1.1.2 Running: bundle install --without development:test --path vendor/bundle --binstubs bin/ --deployment Fetching gem metadata from https://rubygems.org/....... ... -----> Launching... done, v4 http://evening-sky-7498.herokuapp.com deployed to Heroku
You’ll know the app is done being pushed, when you see the “Launching…” text like above.
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://evening-sky-7498.herokuapp.com/. You can also type
heroku open in the terminal to visit the page.