Get Started with Ruby on Rails on Scalingo
Initialize Your Application
$ rails new my-app # # It creates files and run 'bundle install' # $ git init $ git add . $ git commit -m "Base rails application"
Create Your Application on Scalingo
$ scalingo create my-app Git repository detected: remote scalingo added → 'git push scalingo master' to deploy your app
Provision and Configure Your Database
- Go on the dashboard of your application.
- Select the Addons category
- Choose the database you want to use
Add the gem
pg to your
Add the gem
mysql to your
gem 'mysql2', '~> v0.3.18'
Then set the following environment variable:
DATABASE_URL→ Copy the value of
SCALINGO_MYSQL_URLand replace ‘mysql://’ by ‘mysql2://’
To use a MongoDB® database your need to add the gem
mongoid to your
Please refer to this guide.
Setup Your Application Logging
By default, Rails applications don’t write their logs to STDOUT but in a custom file. We expect your application to write all its logging entries to STDOUT and STDERR according to their nature, in accordance to the 12-factor.
Why writing the logs to the standard output?
It is a requirement to let the platform aggregate them and let you browse your application logs in the dashboard or with Scalingo’s command line interface.
Rails 5 and Later
You’ve nothing to do, everything is handled by the platform
Rails 4 and Before
- Add the following gem in your
rails_12factor gem includes two gems, one of them is
rails_stdout_logging. Thanks to it, the application won’t write the logs to
log/production.log file but directly on the standard output.
Serving Static Assets
In a more traditional way to host a Ruby on Rails application, assets would not be served by the application server, but by a proxy web server (Apache/Nginx for instance), but you don’t need that on Scalingo.
Rails 4.2 and Later
You’ve nothing to do, everything is handled by the platform.
Rails 4.1 and Before
- As for the logging: add the following gem in your
gem "rails_12factor". It includes a middleware provided by
sprocketto serve static files located in the
/publicdirectory of your project.
Finalize and Deploy
$ bundle install $ git add . $ git commit -m "Configure application for Scalingo" $ git push scalingo master
To run a migration, you need to use a post-deployment hook.
The Ruby on Rails application starts up before the schema has changed, but does not receive a query. The way ActiveRecord works on Rails is that the schema is loaded into memory on the first query on a given table.
As a result, if operations are started before the migration has been executed (per example initializers or an asynchronous worker), the application may load the schema
pre-migration. A restart could be necessary after the migration.
The best practice is to perform non-destructive migrations, where a column rename is performed in several steps, rather than an
ALTER TABLE renaming a column.
A good example in
strong_migrations gem documentation.
Access Your Application
… Waiting for your application to boot... <-- https://my-app.osc-fr1.scalingo.io -->
A new application will render a 404 error
The page you were looking for doesn't exist.,
but it’s expected. There is nothing in the project, it’s time to build your product!
Specifying a Custom Node.js Runtime
Latest version of Rails application also use Node.js in case ExecJS or Webpacker is detected. The Node.js version built inside the Ruby buildpack is frozen. It is the latest version of the LTS 20.x at the time of writing.
If you ever need to specify a different version of Node.js, you need to setup
the multi buildpacks), in order to use both the Node.js and the Ruby buildpack. The content of your
.buildpacks file must respect the following order between the buildpacks:
You also need to remove the file
bin/yarn if it already exists.
You eventually need to specify the Node.js version in your
You may see the following error when deploying a Rails application which uses Webpacker:
error Command "webpack" not found.
In order to fix this error, execute the locally the following commands:
bundle exec rails yarn:install bundle exec rails webpacker:install
Commit and push the binstubs:
git add bin/* git commit -m "Add Yarn and Webpacker binstubs" git push scalingo master
Use VIPS to Process Image
Since Rails 7 the default image processing tool for ActiveStorage has been replaced from ImageMagick to VIPS. As VIPS isn’t installed by default in our stack, you will need to install the
libvips-dev package using the APT Buildpack.
Some functionalities, for example HEIF support, will be available only by adding optional package dependencies, see VIPS documentation for more information.
Specify a Secret Key Base
Starting with Rails 4.1, you can now specify a secret key base, which is used as the input secret to the application’s key generator.
By default, this value is randomly generated by Scalingo. You can change this default value by setting the
SECRET_KEY_BASE environment variable in your application.