In this first part, we will examine how ActiveStorage treats uploaded data and how to extend this process. The second part will explore how to augment the presentation of uploaded assets.
Without recounting the entire ActiveStorage documentation, in a nutshell, ActiveStorage is an adapter to various forms of storing (mostly) user-generated files in your Ruby on Rails application in a straightforward way. The available storage backends can be divided into:
Note: For the sake of completeness, there are also adapters to directly store binary data in your database, like active_storage-postgresql.
ActiveStorage allows you to transparently attach files to database records for easy access. You have probably already come across this API:
Here, the class methods has_one_attached and has_many_attached are responsible for wiring up your User or Post records with the respective attachments. But how does this magic work?
Under the hood, ActiveStorage uses two database tables generated when you install it. Here are their entries from the database schema definition: