Getting Started with Rails 4.x on Heroku
Last updated October 16, 2024
This article is a work in progress, or documents a feature that is not yet released to all users. This article is unlisted. Only those with the link can access it.
Table of Contents
This article is archived. It no longer receives updates and is here for historical reference only. We can’t guarantee that any statements made are still true or that the instructions still work. This version of Rails is no longer supported by Ruby core. If you’re starting a new application, we recommend you use the most recently released version of Rails.
We recommend using our low-cost plans to complete this tutorial. Eligible students can apply for platform credits through our new Heroku for GitHub Students program.
Ruby on Rails is a popular web framework written in Ruby. This guide covers using Rails 4 on Heroku. For information about running previous versions of Rails on Heroku, see Getting Started with Rails 3.x on Heroku.
If you are already familiar with Heroku and Rails, reference the simplifed Rails 4 on Heroku guide instead. For general information on how to develop and architect apps for use on Heroku, see Architecting Applications for Heroku.
For this guide you will need:
- Basic Ruby/Rails knowledge
- Locally installed version of Ruby 2.0.0+, Rubygems, Bundler, and Rails 4+
- Basic Git knowledge
- A verified Heroku Account
- A subscription to the Eco dynos plan (recommended)
Local Workstation Setup
Install the Heroku Toolbelt on your local workstation. This ensures that you have access to the Heroku command-line client, Foreman, and the Git revision control system. You will also need Ruby and Rails installed.
Once installed, you’ll have access to the $ heroku
command from your command shell. Log in using the email address and password you used when creating your Heroku account:
Note that $
symbol before commands indicates they should be run on the command line, prompt, or terminal with appropriate permissions. Do not copy the $
symbol.
$ heroku login
Enter your Heroku credentials.
Email: schneems@example.com
Password:
Could not find an existing public key.
Would you like to generate one? [Yn]
Generating new SSH public key.
Uploading ssh public key /Users/adam/.ssh/id_rsa.pub
Press enter at the prompt to upload your existing ssh
key or create a new one, used for pushing code later on.
Write your App
To run on Heroku your app must be configured to use the Postgres database, have all dependencies declared in your Gemfile
, and have the rails_12factor
gem in the production group of your Gemfile
You may be starting from an existing app, if so upgrade to Rails 4 before continuing. If not, a vanilla Rails 4 app will serve as a suitable sample app. To build a new app make sure that you’re using the Rails 4.x using $ rails -v
. You can get the new version of rails by running,
$ gem install rails -v 4.2.9 --no-document
Successfully installed rails-4.2.9
1 gem installed
Note: There may be a more recent version of Rails available, we recommend always running the latest. You may want to run Rails 5 on Heroku.
Then create a new app:
$ rails _4.2.9_ new myapp --database=postgresql
Then move into your application directory.
$ cd myapp
If you experience problems or get stuck with this tutorial, your questions may be answered in a later part of this document. Once you experience a problem try reading through the entire document and then going back to your issue. It can also be useful to review your previous steps to ensure they all executed correctly.
If already have an app that was created without specifying --database=postgresql
you will need to add the pg
gem to your Rails project. Edit your Gemfile
and change this line:
gem 'sqlite3'
To this:
gem 'pg'
We highly recommend using PostgreSQL during development. Maintaining parity between your development and deployment environments prevents subtle bugs from being introduced because of differences between your environments. Install Postgres locally now if it is not allready on your system.
Now re-install your dependencies (to generate a new Gemfile.lock
):
$ bundle install
You can get more information on why this change is needed and how to configure your app to run postgres locally see why you cannot use Sqlite3 on Heroku.
In addition to using the pg
gem, you’ll also need to ensure the config/database.yml
is using the postgresql
adapter.
The development section of your config/database.yml
file should look something like this:
$ cat config/database.yml
# PostgreSQL. Versions 9.3 and up are supported.
#
# Install the pg driver:
# gem install pg
# On macOS with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On macOS with MacPorts:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem "pg"
#
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
Be careful here, if you omit the sql
at the end of postgresql
in the adapter
section your application will not work.
Welcome page
Rails 4 no longer has a static index page in production. When you’re using a new app, there will not be a root page in production, so we need to create one. We will first create a controller called welcome
for our home page to live:
$ rails generate controller welcome
Next we’ll add an index page.
In file app/views/welcome/index.html.erb
write:
<h2>Hello World</h2>
<p>
The time is now: <%= Time.now %>
</p>
Now we need to have Rails route to this action. We’ll edit config/routes.rb
to set the index page to our new method:
In file config/routes.rb
, on line 2 add:
root 'welcome#index'
You can verify that the page is there by running your server:
$ rails server
And visiting http://localhost:3000 in your browser. If you do not see the page, use the logs that are output to your server to debug.
Heroku gems
Heroku integration has previously relied on using the Rails plugin system, which has been removed from Rails 4. To enable features such as static asset serving and logging on Heroku please add rails_12factor
gem to your Gemfile
.
At the end of Gemfile
add:
gem 'rails_12factor', group: :production
Then run:
$ bundle install
We talk more about Rails integration on our Ruby Support page.
Specify Ruby version in app
Rails 4 requires Ruby 1.9.3 or above. Heroku has a recent version of Ruby installed by default, however you can specify an exact version by using the ruby
DSL in your Gemfile
. For this guide we’ll be using Ruby 2.
At the end of Gemfile
add:
ruby "2.3.4"
You should also be running the same version of Ruby locally. You can verify by running $ ruby -v
. You can get more information on specifying your Ruby version on Heroku here.
Store your App in Git
Heroku relies on git, a distributed source control managment tool, for deploying your project. If your project is not already in git first verify that git
is on your system:
$ git --help
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
[--super-prefix=<path>] [--config-env=<name>=<envvar>]
If you don’t see any output or get command not found
you will need to install it on your system, verify that the Heroku toolbelt is installed.
Once you’ve verified that git works, first make sure you are in your Rails app directory by running $ ls
:
The output should look like this:
$ ls
Gemfile
Gemfile.lock
README.md
Rakefile
app
bin
config
config.ru
db
lib
log
public
storage
test
tmp
vendor
Now run these commands in your Rails app directory to initialize and commit your code to git:
$ git init
$ git add .
$ git commit -m "init"
You can verify everything was committed correctly by running:
$ git status
On branch main
nothing to commit, working tree clean
Now that your application is committed to git you can deploy to Heroku.
Deploy your application to Heroku
Using a dyno and a database to complete this tutorial counts towards your usage. Delete your app, and database as soon as you’re done to control costs.
Make sure you are in the directory that contains your Rails app, then create an app on Heroku:
$ heroku create --stack heroku-20
Creating app... done, mysterious-gorge-26971, stack is heroku-20
https://mysterious-gorge-26971.herokuapp.com/ | https://git.heroku.com/mysterious-gorge-26971.git
You can verify that the remote was added to your project by running
$ git config --list --local | grep heroku
remote.heroku.url=https://git.heroku.com/mysterious-gorge-26971.git
remote.heroku.fetch=+refs/heads/*:refs/remotes/heroku/*
If you see fatal: not in a git directory
then you are likely not in the correct directory. Otherwise you may deploy your code. After you deploy your code, you will need to migrate your database, make sure it is properly scaled and use logs to debug any issues that come up.
Following changes in the industry, Heroku has updated our default git branch name to main
. If the project you’re deploying uses master
as its default branch name, use git push heroku master
.
Deploy your code:
$ git push heroku main
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.3.4
remote: -----> Installing dependencies using bundler 1.15.2
remote: Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
remote: Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.15.4). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
remote: Fetching gem metadata from https://rubygems.org/..........
remote: Fetching version metadata from https://rubygems.org/..
remote: Fetching dependency metadata from https://rubygems.org/.
remote: Fetching rake 12.0.0
remote: Fetching i18n 0.8.6
remote: Fetching minitest 5.10.3
remote: Installing i18n 0.8.6
remote: Installing rake 12.0.0
remote: Installing minitest 5.10.3
remote: Fetching thread_safe 0.3.6
remote: Installing thread_safe 0.3.6
remote: Fetching builder 3.2.3
remote: Fetching erubis 2.7.0
remote: Installing builder 3.2.3
remote: Fetching mini_portile2 2.2.0
remote: Installing erubis 2.7.0
remote: Installing mini_portile2 2.2.0
remote: Fetching rack 1.6.8
remote: Fetching mime-types-data 3.2016.0521
remote: Installing rack 1.6.8
remote: Installing mime-types-data 3.2016.0521
remote: Fetching arel 6.0.4
remote: Installing arel 6.0.4
remote: Using bundler 1.15.2
remote: Fetching coffee-script-source 1.12.2
remote: Installing coffee-script-source 1.12.2
remote: Fetching execjs 2.7.0
remote: Fetching thor 0.20.0
remote: Installing execjs 2.7.0
remote: Fetching concurrent-ruby 1.0.5
remote: Installing thor 0.20.0
remote: Fetching ffi 1.9.18
remote: Installing concurrent-ruby 1.0.5
remote: Fetching multi_json 1.12.1
remote: Installing multi_json 1.12.1
remote: Fetching json 1.8.6
remote: Installing json 1.8.6 with native extensions
remote: Fetching pg 0.21.0
remote: Installing ffi 1.9.18 with native extensions
remote: Installing pg 0.21.0 with native extensions
remote: Fetching rails_serve_static_assets 0.0.5
remote: Installing rails_serve_static_assets 0.0.5
remote: Fetching rails_stdout_logging 0.0.5
remote: Installing rails_stdout_logging 0.0.5
remote: Fetching rb-fsevent 0.10.2
remote: Installing rb-fsevent 0.10.2
remote: Fetching rdoc 4.3.0
remote: Installing rdoc 4.3.0
remote: Fetching tilt 2.0.8
remote: Installing tilt 2.0.8
remote: Fetching turbolinks-source 5.0.3
remote: Installing turbolinks-source 5.0.3
remote: Fetching tzinfo 1.2.3
remote: Installing tzinfo 1.2.3
remote: Fetching nokogiri 1.8.0
remote: Installing nokogiri 1.8.0 with native extensions
remote: Fetching mime-types 3.1
remote: Installing mime-types 3.1
remote: Fetching rack-test 0.6.3
remote: Installing rack-test 0.6.3
remote: Fetching coffee-script 2.4.1
remote: Installing coffee-script 2.4.1
remote: Fetching uglifier 3.2.0
remote: Installing uglifier 3.2.0
remote: Fetching sprockets 3.7.1
remote: Installing sprockets 3.7.1
remote: Fetching rails_12factor 0.0.3
remote: Installing rails_12factor 0.0.3
remote: Fetching turbolinks 5.0.1
remote: Installing turbolinks 5.0.1
remote: Fetching activesupport 4.2.9
remote: Installing activesupport 4.2.9
remote: Fetching rb-inotify 0.9.10
remote: Installing rb-inotify 0.9.10
remote: Fetching mail 2.6.6
remote: Installing mail 2.6.6
remote: Fetching rails-deprecated_sanitizer 1.0.3
remote: Installing rails-deprecated_sanitizer 1.0.3
remote: Fetching globalid 0.4.0
remote: Installing globalid 0.4.0
remote: Fetching activemodel 4.2.9
remote: Installing activemodel 4.2.9
remote: Fetching jbuilder 2.7.0
remote: Installing jbuilder 2.7.0
remote: Fetching sass-listen 4.0.0
remote: Installing sass-listen 4.0.0
remote: Fetching activejob 4.2.9
remote: Installing activejob 4.2.9
remote: Fetching activerecord 4.2.9
remote: Installing activerecord 4.2.9
remote: Fetching sass 3.5.1
remote: Installing sass 3.5.1
remote: Fetching rails-dom-testing 1.0.8
remote: Fetching loofah 2.0.3
remote: Installing rails-dom-testing 1.0.8
remote: Installing loofah 2.0.3
remote: Fetching rails-html-sanitizer 1.0.3
remote: Installing rails-html-sanitizer 1.0.3
remote: Fetching sdoc 0.4.2
remote: Fetching actionview 4.2.9
remote: Installing sdoc 0.4.2
remote: Installing actionview 4.2.9
remote: Fetching actionpack 4.2.9
remote: Installing actionpack 4.2.9
remote: Fetching railties 4.2.9
remote: Fetching actionmailer 4.2.9
remote: Fetching sprockets-rails 3.2.0
remote: Installing sprockets-rails 3.2.0
remote: Installing actionmailer 4.2.9
remote: Installing railties 4.2.9
remote: Fetching jquery-rails 4.3.1
remote: Fetching rails 4.2.9
remote: Fetching coffee-rails 4.1.1
remote: Installing coffee-rails 4.1.1
remote: Fetching sass-rails 5.0.6
remote: Installing sass-rails 5.0.6
remote: Installing jquery-rails 4.3.1
remote: Installing rails 4.2.9
remote: Bundle complete! 13 Gemfile dependencies, 58 gems now installed.
remote: Gems in the groups development and test were not installed.
remote: Bundled gems are installed into ./vendor/bundle.
remote: The latest bundler is 1.15.4, but you are currently running 1.15.2.
remote: To update, run `gem install bundler`
remote: Bundle completed (27.77s)
remote: Cleaning up the bundler cache.
remote: -----> Installing node-v6.11.1-linux-x64
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote: Running: rake assets:precompile
remote: I, [2017-08-22T14:43:37.636715 #1379] INFO -- : Writing /tmp/build_2c1df257010d0249b8e774d0a81661c0/public/assets/application-da9278e46ebce38e9f8d754b05bbae46591ded89a2ae20880119fd551853710d.js
remote: I, [2017-08-22T14:43:37.637329 #1379] INFO -- : Writing /tmp/build_2c1df257010d0249b8e774d0a81661c0/public/assets/application-da9278e46ebce38e9f8d754b05bbae46591ded89a2ae20880119fd551853710d.js.gz
remote: I, [2017-08-22T14:43:37.648501 #1379] INFO -- : Writing /tmp/build_2c1df257010d0249b8e774d0a81661c0/public/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css
remote: I, [2017-08-22T14:43:37.648845 #1379] INFO -- : Writing /tmp/build_2c1df257010d0249b8e774d0a81661c0/public/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css.gz
remote: Asset precompilation completed (5.59s)
remote: Cleaning assets
remote: Running: rake assets:clean
remote:
remote: ###### WARNING:
remote: No Procfile detected, using the default web server.
remote: We recommend explicitly declaring how to boot your server process via a Procfile.
remote: https://devcenter.heroku.com/articles/ruby-default-web-server
remote:
remote: -----> Discovering process types
remote: Procfile declares types -> (none)
remote: Default types for buildpack -> console, rake, web, worker
remote:
remote: -----> Compressing...
remote: Done: 40.5M
remote: -----> Launching...
remote: Released v5
remote: https://secret-taiga-10886.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/secret-taiga-10886.git
* [new branch] master -> master
It is always a good idea to check to see if there are any warnings or errors in the output. If everything went well you can migrate your database.
Migrate your database
If you are using the database in your application you need to manually migrate the database by running:
$ heroku run rake db:migrate
Any commands after the heroku run
will be executed on a Heroku dyno. You can obtain an interactive shell session by running $ heroku run bash
.
Visit your application
You’ve deployed your code to Heroku. You can now instruct Heroku to execute a process type. Heroku does this by running the associated command in a dyno - a lightweight container which is the basic unit of composition on Heroku.
Let’s ensure we have one dyno running the web
process type:
$ heroku ps:scale web=1
You can check the state of the app’s dynos. The heroku ps
command lists the running dynos of your application:
$ heroku ps
Eco dyno hours quota remaining this month: 1000h 0m (100%)
Eco dyno usage for this app: 0h 0m (0%)
For more information on dyno sleeping and how to upgrade, see:
https://devcenter.heroku.com/articles/eco-dynp-hours#dyno-sleeping
=== web (Eco): bin/rails server -p ${PORT:-5000} -e $RAILS_ENV (1)
web.1: up 2022/11/09 15:24:10 -0800 (~ 2s ago)
Here, one dyno is running.
We can now visit the app in our browser with heroku open
.
$ heroku open
You should now see the “Hello World” text we inserted above.
Heroku gives you a default web url for simplicty while you are developing. When you are ready to scale up and use Heroku for production you can add your own Custom Domain.
View the logs
If you run into any problems getting your app to perform properly, you will need to check the logs.
You can view information about your running app using one of the logging commands, heroku logs
:
$ heroku logs
2022-11-09T23:23:21.343367+00:00 app[api]: Release v1 created by user developer@example.com2022-11-09T23:23:21.343367+00:00 app[api]: Initial release by user developer@example.com2022-11-09T23:23:21.532821+00:00 app[api]: Release v2 created by user developer@example.com2022-11-09T23:23:21.532821+00:00 app[api]: Enable Logplex by user developer@example.com2022-11-09T23:23:23.000000+00:00 app[api]: Build started by user developer@example.com2022-11-09T23:24:02.733681+00:00 app[api]: Set LANG, RACK_ENV, RAILS_ENV, RAILS_LOG_TO_STDOUT, RAILS_SERVE_STATIC_FILES, SECRET_KEY_BASE config vars by user developer@example.com2022-11-09T23:24:02.733681+00:00 app[api]: Release v3 created by user developer@example.com2022-11-09T23:24:03.882779+00:00 app[api]: Attach DATABASE (@ref:postgresql-defined-88230) by user developer@example.com2022-11-09T23:24:03.882779+00:00 app[api]: Running release v4 commands by user developer@example.com2022-11-09T23:24:03.895277+00:00 app[api]: @ref:postgresql-defined-88230 completed provisioning, setting DATABASE_URL. by user developer@example.com2022-11-09T23:24:03.895277+00:00 app[api]: Release v5 created by user developer@example.com2022-11-09T23:24:04.292076+00:00 app[api]: Deploy a2830cc3 by user developer@example.com2022-11-09T23:24:04.292076+00:00 app[api]: Release v6 created by user developer@example.com2022-11-09T23:24:04.309828+00:00 app[api]: Scaled to console@0:Eco rake@0:Eco web@1:Eco by user developer@example.com2022-11-09T23:24:06.386981+00:00 heroku[web.1]: Starting process with command `bin/rails server -p ${PORT:-5000} -e production`
2022-11-09T23:24:07.000000+00:00 app[api]: Build succeeded
2022-11-09T23:24:09.769468+00:00 app[web.1]: => Booting Puma
2022-11-09T23:24:09.769508+00:00 app[web.1]: => Rails 7.0.4 application starting in production
2022-11-09T23:24:09.769509+00:00 app[web.1]: => Run `bin/rails server --help` for more startup options
2022-11-09T23:24:10.804322+00:00 app[web.1]: Puma starting in single mode...
2022-11-09T23:24:10.804359+00:00 app[web.1]: * Puma version: 5.6.5 (ruby 2.7.2-p137) ("Birdie's Version")
2022-11-09T23:24:10.804360+00:00 app[web.1]: * Min threads: 5
2022-11-09T23:24:10.804360+00:00 app[web.1]: * Max threads: 5
2022-11-09T23:24:10.804360+00:00 app[web.1]: * Environment: production
2022-11-09T23:24:10.804360+00:00 app[web.1]: * PID: 4
2022-11-09T23:24:10.804597+00:00 app[web.1]: * Listening on http://0.0.0.0:17576
2022-11-09T23:24:10.810258+00:00 app[web.1]: Use Ctrl-C to stop
2022-11-09T23:24:10.899039+00:00 heroku[web.1]: State changed from starting to up
You can also get the full stream of logs by running the logs command with the --tail
flag option like this:
$ heroku logs --tail
Dyno sleeping and scaling
By default, your app is deployed on an eco dyno. Eco dynos will sleep after a half hour of inactivity and they can be active (receiving traffic) for no more than 18 hours a day before going to sleep. If an eco dyno is sleeping, and it hasn’t exceeded the 18 hours, any web request will wake it. This causes a delay of a few seconds for the first request upon waking. Subsequent requests will perform normally.
$ heroku ps:scale web=1
To avoid dyno sleeping, you can upgrade to a Basic or Professional dyno type as described in the Dyno Types article. For example, if you migrate your app to a professional dyno, you can easily scale it by running a command telling Heroku to execute a specific number of dynos, each running your web process type.
Console
Heroku allows you to run commands in a one-off dyno - scripts and applications that only need to be executed when needed - using the heroku run
command. Use this to launch a Rails console process attached to your local terminal for experimenting in your app’s environment:
$ heroku run rails console
irb(main):001:0> puts 1+1
2
Rake
Rake can be run as an attached process exactly like the console:
$ heroku run rake db:migrate
Webserver
By default, your app’s web process runs rails server
, which uses Webrick. This is fine for testing, but for production apps you’ll want to switch to a more robust webserver. On Cedar, we recommend Puma as the webserver. Regardless of the webserver you choose, production apps should always specify the webserver explicitly in the Procfile
.
First, add Puma to your application Gemfile
:
At the end of Gemfile
add:
#gem 'puma'
Then run
$ bundle install
Now you are ready to configure your app to use Puma. For this tutorial we will use the default settings of Puma, but we recommend generating a config/puma.rb
file and reading more about configuring your application for maximum performance by reading the Puma documentation
Finally you will need to tell Heroku how to run your Rails app by creating a Procfile
in the root of your application directory.
Procfile
Change the command used to launch your web process by creating a file called Procfile and entering this:
In file Procfile
write:
web: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}
Note: The case of Procfile
matters, the first letter must be uppercase.
We recommend generating a puma config file based on our Puma documentation for maximum performance.
Set the RACK_ENV
to development in your environment and a PORT
to connect to. Before pushing to Heroku you’ll want to test with the RACK_ENV
set to production since this is the enviroment your Heroku app will run in.
$ echo "RACK_ENV=development" >>.env
$ echo "PORT=3000" >> .env
You’ll also want to add .env
to your .gitignore
since this is for local enviroment setup.
$ echo ".env" >> .gitignore
$ git add .gitignore
$ git commit -m "add .env to .gitignore"
Test your Procfile locally using Foreman:
$ gem install foreman
You can now start your web server by running
$ foreman start
18:24:56 web.1 | I, [2013-03-13T18:24:56.885046 #18793] INFO -- : listening on addr=0.0.0.0:5000 fd=7
18:24:56 web.1 | I, [2013-03-13T18:24:56.885140 #18793] INFO -- : worker=0 spawning...
18:24:56 web.1 | I, [2013-03-13T18:24:56.885680 #18793] INFO -- : master process ready
18:24:56 web.1 | I, [2013-03-13T18:24:56.886145 #18795] INFO -- : worker=0 spawned pid=18795
18:24:56 web.1 | I, [2013-03-13T18:24:56.886272 #18795] INFO -- : Refreshing Gem list
18:24:57 web.1 | I, [2013-03-13T18:24:57.647574 #18795] INFO -- : worker=0 ready
Looks good, so press Ctrl-C to exit and you can deploy your changes to Heroku:
$ git add .
$ git commit -m "use puma via procfile"
$ git push heroku main
Check ps
, you’ll see the web process uses your new command specifying Puma as the web server
$ heroku ps
Eco dyno hours quota remaining this month: 1000h 0m (100%)
Eco dyno usage for this app: 0h 0m (0%)
For more information on dyno sleeping and how to upgrade, see:
https://devcenter.heroku.com/articles/eco-dyno-hours#dyno-sleeping
=== web (Eco): bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development} (1)
web.1: starting 2022/11/09 15:24:37 -0800 (~ 6s ago)
The logs also reflect that we are now using Puma:
$ heroku logs
Rails Asset Pipeline
There are several options for invoking the Rails asset pipeline when deploying to Heroku. For general information on the asset pipeline please see the Rails 3.1+ Asset Pipeline on Heroku Cedar article.
The config.assets.initialize_on_precompile
option has been removed is and not needed for Rails 4. Also, any failure in asset compilation will now cause the push to fail. For Rails 4 asset pipeline support see the Ruby Support page.
Troubleshooting
If you push up your app and it crashes (heroku ps
shows state crashed
), check your logs to find out what went wrong. Here are some common problems.
Runtime dependencies on development/test gems
If you’re missing a gem when you deploy, check your Bundler groups. Heroku builds your app without the development
or test
groups, and if your app depends on a gem from one of these groups to run, you should move it out of the group.
One common example using the RSpec tasks in your Rakefile
. If you see this in your Heroku deploy:
$ heroku run rake -T
Running `bundle exec rake -T` attached to terminal... up, ps.3
rake aborted!
no such file to load -- rspec/core/rake_task
Then you’ve hit this problem. First, duplicate the problem locally:
$ bundle install --without development:test
…
$ bundle exec rake -T
rake aborted!
no such file to load -- rspec/core/rake_task
Now you can fix it by making these Rake tasks conditional on the gem load. For example:
Rakefile
begin
require "rspec/core/rake_task"
desc "Run all examples"
RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = %w[--color]
t.pattern = 'spec/**/*_spec.rb'
end
rescue LoadError
end
Confirm it works locally, then push to Heroku.
Done
You now have your first application deployed to Heroku. The next step is to deploy your own application. If you’re interested in reading more you can read more about Ruby on Heroku at the Devcenter.