How to Upload Images In Your Rails Project Using Active Storage

Leonora Squires
The Startup

--

*Note this is for projects that use Rails as a front end framework*

So you want to upload images in your Rails project?

Well you’re in the right place!

Today you’ll get a brief overview of what Active Storage is, and how to set up and use it to upload images in your Rails project.

Active Storage

What’s Active Storage? Well it’s a very simple, but powerful way of uploading files to cloud storage services (Amazon S3, Google Cloud Storage, or Microsoft Azure Storage).

Active Storage also provides disk service for local deployment and testing. It’s able to attach files to Active Record objects without you having to create another column in your model tables.

Curious about how this work? Well, long story short, Active Storage uses polymorphic associations through the Attachment join model, which then connects to the Blob model (this model stores attachment metadata like filename, content-type, etc. and their identifier key). Both models are built-in models backed by Active Record.

Installation

Okay, let’s get into how to set up Active Storage in your application. First you’re going to run rails active_storage:install into…

--

--