Skip to content

Instantly share code, notes, and snippets.

@raghubetina
Last active January 5, 2024 04:40
Show Gist options
  • Save raghubetina/2891a498de400cbe8f1e to your computer and use it in GitHub Desktop.
Save raghubetina/2891a498de400cbe8f1e to your computer and use it in GitHub Desktop.
Heroku Cheatsheet

Heroku Cheatsheet

Get the Heroku toolbelt

Sign up for a Heroku account and install the toolbelt if you haven't already.

Prepare your application

In your Gemfile, add

group :production do
  gem 'pg'
  gem 'rails_12factor'
end

and replace

gem 'sqlite3'

with

group :development do
  gem 'sqlite3'
end

Next, from the command line,

bundle install --without production

Finally, commit these changes using the Desktop App or from the command line:

git add -A
git commit -m "Heroku changes"

Add Heroku as a git destination

From the command line,

heroku create your-app-name-here

If the name is available, you will get a URL of http://your-app-name-here.herokuapp.com. If not, try again.

Send your code to Heroku

From the command line,

git push heroku master

It may take a while for Heroku to receive your code, detect that it is a Rails application, bundle install, and deploy. Once finished you should be able to visit your site with the shorcut

heroku open

Every time you are ready to deploy a new version of your app, you need to again do

git push heroku master

to send your latest commits to Heroku. You can continue using GitHub to store and colloborate on your code just the same as before; you just have two destinations now to send your code to instead of one.

Migrate your database

You still need to migrate your database and other setup tasks. Prefix any commands that you want to run on your Heroku machine with heroku run. For example,

heroku run rake db:migrate
heroku run rake db:seed
heroku run rails c

Note: if you used a column type of belongs_to when generating scaffolds with foreign key columns, AND you used a non-conventional name for them, you will need to modify your migration files. TODO complete this.

See error messages happening in production

In-browser error messages are not descriptive while in production mode, since you don't want to scare users.

To see error messages for your production server,

heroku logs --tail

This gives you a view into your production server log.

Custom Domains

You can use your own custom domain for your Heroku app. You will first need to purchase a domain from a provider like Google Domains.

@ppartha0
Copy link

I was having issues with authentication on Heroku; at the command line I received the following error:

▸ HTTP Error: https://api.heroku.com/login 400 Bad Request ▸ Invalid response from API. ▸ HTTP 400 ▸ {email password} ▸ ▸ Are you behind a proxy? ▸ https://devcenter.heroku.com/articles/using-the-cli#using-an-http-proxy

I was able to fix the issue by running the following in my C9 workspace:

wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh This is from https://devcenter.heroku.com/articles/heroku-cli

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment