# config/storage.yml test : service : Disk root : local : service : Disk root : # Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) # amazon: # service: S3 # access_key_id: # secret_access_key: # region: us-east-1 # bucket: your_own_bucket # Remember not to checkin your GCS keyfile to a repository # google: # service: GCS # project: your_project # credentials: # bucket: your_own_bucket # Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) # microsoft: # service: AzureStorage # storage_account_name: your_account_name # storage_access_key: # container: your_container_name # mirror: # service: Mirror # primary: local # mirrors: That's right - no more creating additional columns in your models for images and files.īlobs are records that contain the metadata of the file (such as content type, size, filename etc.) and an encoded key which points to the file location on the service (be it local or cloud).Īttachments associates your models with blobs.Īfter the migration, you need to add associations to attachments in your model: index, name: "index_active_storage_attachments_uniqueness", unique: true end end endĪctiveStorage will use these tables to keep track of your uploads via polymorphic associations. references :record, null: false, polymorphic: true, index: false t. index, unique: true end create_table :active_storage_attachments do | t | t. # db/migrate/20180407102457_create_active_storage_tables.active_storage.rb class CreateActiveStorageTables < ActiveRecord :: Migration def change create_table :active_storage_blobs do | t | t. This will create new migrations for ActiveStorage to use - more precisely, it will create active_storage_blobs and active_storage_attachments tables in your database. If you are updating your existing Rails project, right after upgrading Rails to 5.2 you need to run command rails active_storage:install. Adapting your Rails project to Active Storage Let's check out what needs to be done when adapting your project to ActiveStorage. This means Rails developers no longer have to use third-party libraries like CarrierWave for example. The files are uploaded to cloud storage services like Amazon S3, Google Cloud Storage or Microsoft Azure Storage and then attached to Active Record objects in the app.