Active Storage checklist (s3)Tuesday, January 25, 2022 at 10:57:39 PM
Active Storage is an absolute wonder. If you implemented file storage in the aughts, Active Storage may make you weep for joy.
While Active Storage is easy to implement (provided you know your way around the seven circles of hell also known as AWS), it is not intuitive and the documentation is overly exhaustive for someone who isn’t implementing active storage for the first time.
Here is a quick checklist reference for implementing Active Storage with s3.
- Ensure the image_processing and aws gems are installed
gem "image_processing", ">= 1.2" gem 'aws-sdk' gem "aws-sdk-s3", require: false
- Add your s3 bucket credentials in storage.yml
amazon: service: S3 access_key_id: ‘****’ secret_access_key: ‘****’ region: 'us-east-1' bucket: ‘img_bucket’
- Configure your app to use the amazon credentials in your environment configuration (i.e. development.rb)
config.active_storage.service = :amazon
- Add image macro to model
has_one_attached :image has_many_attached :images
- Serve image in views
<%= image_tag project.img %>
This post was not edited. If you see a typo, let me know and I'll fix it.