Time: 2021-04-03 23:44 UTC+8:00
Author: vonhyou
This article introduces the professional way of deploying Rails app on Heroku.
Force SSL
Modify the file config/environments/production.rb in your Rails app:
# Uncomment this 
config.force_ssl = true
Heroku provide free ssl certificate and it's not necessary to do something else.
Switch to Puma
- Add a gem called 
pumato theGemfileand install it. - Rewrite the file 
config/puma.rb 
# Puma configuration file.
max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
threads min_threads_count, max_threads_count
port        ENV.fetch("PORT") { 3000 }
environment ENV.fetch("RAILS_ENV") { ENV['RACK_ENV'] || "development" }
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
workers ENV.fetch("WEB_CONCURRENCY") { 2 }
preload_app!
plugin :tmp_restart
- Create 
Procfile 
$ touch ./Procfile
- Write 
Procfile 
web: bundle exec puma -C config/puma.rb
- Configurate database for production
 
# SQLite. Versions 3.8.0 and up are supported.
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000
development:
  <<: *default
  database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: db/test.sqlite3
production:
  adapter:  postgresql
  encoding: unicode
  pool:     <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  database: <APPNAME>_production
  username: <APPNAME>
  password: <%= ENV['<APPNAME>_DATABASE_PASSWORD'] %>
Declare Ruby Version
Modify Gemfile
ruby '2.6.5' # your version
    
Top comments (3)
Why is better puma for heroku?
It depends, according to the documentation:
Link: Deploying Rails Applications with the Puma Web Server
Thanks!
I have been using puma because it's the "default" way in Heroku, at least for me it's super easy to use it.