Rails 5.2 added a built-in solution for handling file uploads using Active Storage.
Let’s say, we have an
Candidate model that has two attachments
Before Rails 6.1, only one cloud storage service (Amazon S3, Google cloud storage, Microsoft Azure storage) could be used for overall application.
But, there could be cases where our application might require to upload images to different storage services.
In Rails 6.1
For the above example, let’s say we want to upload
We need to pass
service parameter to
has_one_attached method as shown
In the above example,
resume of the candidate is stored to
storage.yml can be configured as below for multiple storage services:
serviceis not specified the default
config/environmentsis used for storage.
If specified service is not properly configured,
has_one_attachedwould throw an error.
If our project is already using Active Storage and when we upgrade to Rails 6.1, we should run
rake app:updateto make sure
service_namecolumn is added to the internal