Rails 3.x Application 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 3.X or higher. For other versions, see:
Rails 3.X applications behave like Ruby applications with the following additions.
Auto-Detection
Heroku detects that an app is a Rails 3.x app when:
Gemfile.lock
contains a railties
gem
the railties
gem version is 3.0.0 or later, and earlier than 4.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”
Add-ons
Adds the same add-ons as a pure Ruby app.
Process Types
If you don’t include a Procfile
, Rails 3 apps define a web and console process type at deploy time:
web: bundle exec rails server -p $PORT
console: bundle exec rails console
On Heroku, we recommend Puma as the webserver. Regardless of the webserver you choose, always specify it explicitly in the Procfile
on production apps.
As a special case to assist in migration from Bamboo, Ruby apps that bundle the thin
gem get this web process type:
web: bundle exec thin start -R config.ru -e $RACK_ENV -p $PORT
Compile Phase
As a final task in the compilation phase, the assets:precompile
Rake task executes. This task compiles all assets and puts them in your public directory. For more information refer to Rails Asset Pipeline on Heroku.
Plugin Injection in Rails 3
By default, Heroku injects plugins in Rails 3.x applications to ensure applications get the most out of the Heroku platform. The two plugins injected are rails_stdout_logging
and rails3_serve_static_assets
.
- A Rails stdout plugin is injected.
- A static assets plugin is automatically injected.
If you include the rails_12factor
gem, then no plugin injection is performed at all. All the configurations are made via the gem. Put this gem in your :production
group to avoid a bug in development that causes you to see duplicate logs. This bug was fixed in later versions of Rails.
To avoid this injection in Rails 3, include the rails_12factor
gem in your application Gemfile:
gem 'rails_12factor'
Stdout
The rails_stdout_logging
gem ensures that your logs get sent to standard out.
Heroku treats logs as streams of events, rather than files. By piping logs to stdout
, your logs get captured and consolidated across multiple dynos by Logplex, which makes them available from the command line, $ heroku logs --tail
, or from logging add-ons.
Static Assets
The rails3_serve_static_assets
gem lets the web process serve static assets.