An Introduction to Active Storage

Active Storage is an important new service that came with the Rails 5.2 update, giving us an easy way to store files to a cloud storage service.

You can upload assets and files directly to Amazon S3, Google Cloud Storage, or Microsoft Azure Storage and attach those files to your Active Record objects.

It comes with support for local environments for development and testing, as well as mirroring support for easy backups and migrations.

Why Use Active Storage?

Fair question - why do we need this? Can't we just store our images in our Rails app using the standard asset pipeline?

Sort of.

How to Learn AWS
How to Learn AWS
Learn AWS the easy way, become a leader on your team.
How to Learn AWS
LEARN MORE

You won't be able to allow uploads or manipulate your assets if this is the only way you currently serve files. In other words, you can't easily add or remove images without dragging them into your project and redeploying your site.

Also, the asset pipeline is not always fast. It's super convenient and I'll admit I use it because it's sometimes "good enough" but it's really not that fast.

It gives you some optimizations out of the box that are big performance improvements, but by default, everything is still served from your server which introduces other problems.

Since it stores your files on the server, your server has to spend time and resources loading not just your website content but also all of your images. There's also likely a ton of latency since your server is unlikely in a location that is physically close to all of your visitors (this is where using a CDN can really help).

Modern search engines are tracking the speed of your website and in my opinion, this is one of the lowest hanging fruits in terms of making your site super fast.

Also, a fast site means a better experience for your website visitors which is also important so they stick around and don't regret visiting!

Final Words

Hopefully this gave you a good understanding of what Active Storage is, but now you'll want to figure out how to actually install it and use it in your project.

Check out this guide on installing, configuring, and using Active Storage!

Featured
Level up faster
Hey, I'm Nick Dill.

I help people become better software developers with daily tips, tricks, and advice.
Related Articles
More like this
How to Export to CSV with Ruby on Rails
Adding Active Storage to your Rails Project
What is MVC and Why Should I Use It?