đź’ľ
Cheat Sheet
  • Cheat Sheet
  • Git
    • Initialize a new project
    • Make a new commit
    • Revert the most recent commit
    • Create a new branch
    • Setup terminal prompt to show the current git branch
    • Merge a branch into the current branch
    • Push a new branch up to GitHub (if it doesn’t exist there yet)
    • Pull a new branch from to GitHub to a second computer (if it doesn’t exist there yet)
    • Go back to an older commit and re-work from there
    • Delete a git branch
  • Rails
    • Setup Rails 8 w/ SQLite & Solid Cable, Cache & Queue
    • Stripe Pay Gem
      • Running Stripe Test Mode Locally
    • Setup new Rails app
      • Start a new Rails App (v8)
      • Start a new Rails App (v7)
      • Clone Instrumental Template to a new app
    • Rails 7 Turbo/Hotwire Cheatsheet
    • ActiveStorage with AWS S3
    • Live reloading with webpack-dev-server
    • Sidekiq & Redis
      • Setup Sidekiq in a Rails 8 app
      • Clear sidekiq queue
      • Start jobs worker
    • Setup Solid Queue/Cable/Cache in Rails 8 to share a single database
    • Run rspec tests
      • ZipMessage Tests Commands
      • Can't run rspec tests: ActiveRecord::StatementInvalid: PG::DuplicateTable: ERROR: relation "thing"
    • Acts As Tenant (using Rails console)
    • Reset database & re-run migrations
    • Ultrahook for testing email to app
    • Troubleshooting
      • Manage node versions using NVM
      • Webpacker bugs
      • Tailwind updates not showing
      • Fix orphaned migrations
      • rspec error: session not created: This version of ChromeDriver only supports Chrome version
      • “PG::ConnectionBad” error when running local rails server
        • Postgres not started (PG:ConnectionBad error)
    • OLD
      • Start a new Rails app (v6)
        • Install Tailwind CSS on a Rails Project
        • Install Stimulus.js on Rails
        • Install RSpec, Capybara, FactoryBot
        • Install Devise Masqerade
    • Hosting
      • Hatchbox.io + Digital Ocean
      • Fly.io rails app hosting
      • Render rails app hosting
      • Set up a Rails site on Heroku
        • Fix Sidekiq on Heroku
        • Setup app on Heroku for a Client
    • Edit Rails Credentials
    • Run subdomains on local
  • Misc
    • Terminal shortcuts
    • ngrok for tunneling
    • Set up a new Mac
    • Mailcatcher
  • Statamic
  • Forge / Statamic
    • Run Statamic (for Clarityflow) locally
    • Set up to SSH into Forge server
    • Production deploy failed. Resolve by SSH & resolve git conflicts.
  • Old (not using anymore)
    • Heroku
      • Push to Heroku
        • Can't push to heroku. Updates were rejected because the remote contains work you dont have locally
      • Create a Heroku App from command line
      • Set up remotes for staging and production apps
      • Run the Rails Console on Heroku
      • Migrate database on Heroku
      • Make database backups
      • Restart Heroku Dynos
      • Point a root domain (non-subdomain) to heroku
    • Middleman
      • Start a new middleman site from my template
    • Jekyll
      • Start a new Jekyll site from my template
      • Run and work on my Jekyll site
    • Netlify
      • Setup a Jekyll site on Netlify
      • Push to Staging & Production on Netlify
    • Laravel
      • Start a new Laravel app
      • Setup a Mac for running Laravel
    • Design
      • Icomoon Fonts in Rails
    • Sync Sublime Text settings across macs
    • Run a rails project on a new mac for the first time
    • Customize terminal prompt for bash
  • Cursor
    • .cursorrules for Rails + Linear issue writing
  • Mac Environment
    • Install Homebrew for both arm64 and x86
    • Installing Ruby
    • Customize terminal prompt for zsh to show git branch
    • Open terminal in arm64 or Rosetta mode
    • Install Homebrew
Powered by GitBook
On this page
  • Create app(s) for staging and production
  • Deploy from GitHub
  • First deployment + Setting up Dynos
  • Setup Vars & Staging Environment
  • Setup the Postgres Database on Heroku
  • (if Rails 8+ and if using Redis instead of solid cable...)
  • Migrate the database using Heroku CLI
  • Setup Heroku-Data for Redis add-on (for running Sidekiq)
  • Fix Sidekiq for Heroku
  • Setup TablePlus to connect to the Heroku database
  • Update Procfile with additional lines...
  • Restart servers / dynos
  • Check Heroku logs
  1. Rails
  2. Hosting
  3. Set up a Rails site on Heroku

Setup app on Heroku for a Client

You can do the following when you (hi@briancasel.com) are invited to client's "Team" in Heroku. You only need member permissions (you don't need admin permissions to do the following).

While it's possible to do all of the following using Heroku's CLI and appending --team teamname to all CLI commands, I find it's easier (and safer) to just use Heroku's dashboard to do the following:

Create app(s) for staging and production

If no apps are created in the Heroku Team yet, create them in the interface. Name them appname-staging and appname-production.

Deploy from GitHub

To do the first (and future) deployments, the best option is to connect the GitHub Repo.

Go to the Deploy tab and follow instructions for connecting the GitHub repo for this project to this app.

First deployment + Setting up Dynos

Before you can create any dynos or database, you must do the first deployment.

In the base directory of the project, create a file named Procfile (use capital P and no file extension).

The content can just be this, assuming it's a basic Rails app with no background workers:

web: bundle exec rails server -p $PORT

Commit that to github.

Deploy to Heroku manually in the Deploy tab -> Select the branch to deploy to this app (I typically create a git branch called staging and deploy that branch to the staging site. main branch gets deployed to the production site).

After deployment, you should now see a "Basic" web dyno automatically setup for this app.

Setup Vars & Staging Environment

In Heroku, go to "Settings" -> "Config Vars" and do the following:

If this is the staging app, then change:

  • RAILS_ENV -> change from production to staging

  • RACK_ENV -> change from production to staging

Add an environment variable for RAILS_MASTER_KEY and set its value to the key that is in the project: config/credentials/staging.key

Setup the Postgres Database on Heroku

In Resources -> "Add-ons" -> Find "Heroku Postgres" and add this to the app. It should default to its lowest pricing tier.

(if Rails 8+ and if using Redis instead of solid cable...)

  1. Remove gem 'solid_cable' and add gem 'redis' then bundle install.

  2. Update config/cable.yml to this (replace "appname"):

development:
  adapter: redis
  url: redis://localhost:6379/1

test:
  adapter: test

production:
  adapter: redis
  url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
  channel_prefix: appname_production

Migrate the database using Heroku CLI

Since this is a client's "team" in heroku, we must include the --app flag when running commands.

heroku run rails db:migrate --app appname

Setup Heroku-Data for Redis add-on (for running Sidekiq)

Assuming your app will have background jobs (most do):

Resources -> "Add-ons" -> Find "Heroku Key-Value Store" and add it to the app.

Fix Sidekiq for Heroku

Setup TablePlus to connect to the Heroku database

In Heroku -> Resources -> Heroku Postgres -> Settings -> Find all the credentials you'll need when setting up the database connection in TablePlus on Mac.

Update Procfile with additional lines...

  • Add worker (for running sidekiq jobs)

  • Add release command to always run db migrations after deployments.

Now that the database has been setup on Heroku, you can update the Procfile to include the following lines:

web: bundle exec rails server -p $PORT
worker: bundle exec sidekiq
release: bundle exec rails db:migrate

After re-deploying, you should now see 2 dynos: a web and a worker dyno. Turn both to ON.

Restart servers / dynos

After creating all of the above, you'll probably need to restart the dynos in order for everything to work.

In Heroku dashboard -> "More" menu -> "Restart dynos"

Check Heroku logs

You can watch Heroku logs from within Heroku's dashboard by going to "More" menu -> "Logs"

Or you can run this:

heroku run logs -t --app appname

PreviousFix Sidekiq on HerokuNextEdit Rails Credentials

Last updated 4 months ago

Sidekiq jobs won't work on heroku without this.

See my notes here.