Post

The ephemeral hard drive. Or how Rails Active Storage doesn't work on Heroku

The ephemeral hard drive. Or how Rails Active Storage doesn't work on Heroku

The problem

Apperantly heroku has a ephemeral hard drive, meaning it resets after some time & it isn’t the same between the differnet “dynos” https://devcenter.heroku.com/articles/active-storage-on-heroku

Who could have guessed….

So, in order to have files attached to your models in Ruby on Rails, meaning “in order for Active Storage to work” you need to use some other adapter.

The solution

We store the files in an S3 bucket… Then we use the links AWS provides to access the files

We add gem "aws-sdk-s3" to the Gemfile. Then, we edit production.rb and storage.yml:

1
config.active_storage.service = ENV["AWS_BUCKET"].present? ? :amazon : :local
1
2
3
4
5
6
7
# ...
amazon:
  service: S3
  access_key_id: <%= ENV["AWS_ACCESS_KEY_ID"] %>
  secret_access_key: <%= ENV["AWS_SECRET_ACCESS_KEY"] %>
  region: <%= ENV.fetch("AWS_REGION", "us-east-1") %>
  bucket: <%= ENV["AWS_BUCKET"] %>

I got root access credentials from aws, because I have no clue what is going on there. It works…

This post is licensed under CC BY-NC 4.0 by the author.