Whilst upgrading a Rails 5 app to Rails 6 (the Rails 7 upgrade is soon to follow) we discovered an issue when running the app in production mode:
1 /lib/active_storage/engine.rb:131:in `block (2 levels) in <class:Engine>': Couldn't find Active Storage configuration in /var/www/app/releases/20220108194933/config/storage.yml (RuntimeError)
The error is coming from ActiveStorage, which is a Rails feature that was added in Rails 5.2. ActiveStorage allows Rails apps to upload files to cloud storage providers without the need for a gem, such as Carrierwave.
The exception only occurs when running the app in production mode so we missed it until late in the upgrade process.
How to fix it
Turns out, the fix is very simple. You just need to create a file called
config/storage.yml. Technically, that’s all that’s required. However, we advise you to add some sensible defaults:
1 2 3 4 5 6 7 local: service: Disk root: <%= Rails.root.join("storage") %> test: service: Disk root: <%= Rails.root.join("tmp/storage") %>
This config defines two services:
test. You can then configure your Rails environments to use these services:
1 2 # config/environments/development.rb config.active_storage.service = :local
1 2 # config/environments/production.rb config.active_storage.service = :local
1 2 # config/environments/test.rb config.active_storage.service = :test
If you want to use a cloud service in the future, for example S3, you would create a new service in
config/storage.yml and modify
config/environments/production.rb to reference the new service.