Heroku
What is it?
Github only supports static front-end sites, so we need something more robust and scalable for our Rails apps. Heroku has everything that we need for this:
- Dynos - run virtually any language
- Database - always postgres
- Tools and components
- Connects with heaps of other applications (Salesforce etc.)
- Good support
See here for more.
Heroku is completely based on Git, meaning that it relies on us pushing code up etc. It can be difficult, though it is ten times easier than making our own server.
Steps for Deploying a Rails app to Heroku
- Make an account - here.
- Install the heroku toolbelt - see here or use
brew install heroku - Make sure that it has worked
heroku --versionwhich heroku
- Log in -
heroku login - Make your Rails app
- 'Deploy Early, Deploy Often'
- Set the app up with PostgreSQL
rails new app_name --database=postgresqlrails new app_name -d postgresql
- Change into the app directory and run
bundle installto install all Gems and dependencies - At the end of the Gemfile, add this line -
gem 'rails_12factor', group: :productionand then runbundle installagain - Make it a git repository
- Run
git initin the root folder of the project git add .,git commit -m "Your commit message."- Run
git statusto make sure everything has worked
- Run
- Run
heroku create - Run
git config --list | grep herokuto make sure it has worked - Run
git push heroku master - Run
heroku run rake db:migrate- Any command prefixed by
heroku runwill obviously run on the heroku terminal
- Any command prefixed by
- Ensure that you have a running server, run
heroku ps:scale web=1 - Run
heroku psto make sure that that has all worked - Run
heroku opento do exactly what you imagine
For this in far more detail, see here.
Common Heroku Commands
heroku run rake db:etc.(create, seed, migrate etc.)heroku run rails consoleheroku logs- Shows the rails server (once off)heroku logs --tail- Shows the live server