Rails App Behavior on Heroku
Last updated September 17, 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 describes the behavior of Heroku apps using Rails 5.X or higher. For older versions, see:
Rails apps behave like Ruby applications with the following additions.
Auto-Detection
Heroku detects that an app is a Rails app and the version it’s on by the version of the railties
gem in Gemfile.lock
:
- Rails 5.X for version is 5.0.0 beta or later, and earlier than 6.0.0.
- Rails 6.X for version is 6.0.0 beta or later, and earlier than 7.0.0.
- Rails 7.X for version is 7.0.0 beta or later, and earlier than 8.0.0.
When Heroku recognizes a deployed app as a Rails application, we respond with -----> Ruby/Rails app detected
at deploy time.
$ git push heroku main
-----> Ruby/Rails app detected
Config Vars
We set the following environment variables, in addition to the ones we set for Ruby Application Behavior on all Ruby apps.
RAILS_ENV
=> “production”RACK_ENV
=> “production”RAILS_LOG_TO_STDOUT
=> “enabled”RAILS_SERVE_STATIC_FILES
=> “enabled”
Add-ons
Adds the same add-ons as a pure Ruby app.
Process Types
If you don’t include a Procfile
, Rails 5+ apps define a web and console process type at deploy time:
web: bundle exec bin/rails server -p $PORT -e $RAILS_ENV
console: bundle exec bin/rails console
Regardless of the webserver you choose, always specify the webserver explicitly in the Procfile
on production apps.
Compile Phase
As a final task in the compilation phase, the assets:precompile
Rake task is executed if you have a assets:precompile
Rake task defined, and don’t have a public/assets/manifest-*.json
file. This task compiles all assets and puts them in your public directory. If the rake detection or the asset compilation task fails, the deploy fails as well. For more information, refer to Rails Asset Pipeline on Heroku.
Plugin Injection in Rails 5+
Rails 5+ no longer supports plugin functionality, so Heroku’s support for Rails 5 no longer injects any. Previously in Rails 4, we required the gem rails_12factor
to enable logging and static file service. New applications now work out of the box. If you’re upgrading an application see:
- Getting Started with Rails 7 on Heroku
- Getting Started with Rails 6 on Heroku
- [Getting Started on Rails 5 on Heroku]](getting-started-with-rails5#heroku-gems).