Trix / ActionText / ActiveStorage

tl;dr Trix is unmaintained; ActionText is tightly coupled to ActiveStorage

I’m not sure if “A May Of WTFs” is still a thing in July, but here goes:

Rails is great. It’s incredible how stable it is, especially the ease of upgrades with the last couple of major versions. There’s ton of great functionality and ton more being added! I love it! Thank you all! :heart:

Coming from that state of mind, I was happy to see the new additions to Rails: ActiveStorage, ActionText, and its underlying editor Trix.

Here’s a little story of my new Rails project (started in 2020):

I just started a new Rails project and connected ActiveStorage to S3. The files being uploaded were all to be public domain, but for some reason ActiveStorage encrypts the name using secure global ID and that’s:

  1. Killing the performance of my Rails app, as now all file requests have to go through my Rails app
  2. There’s no way to turn this off (none that I found)

So I decided to abandon ActiveStorage and switched to something else for file uploads. This sucks. This is not the “Rails is omakase” I heard DHH talking about.

This brings me to ActionText. With ActiveStorage disabled, ActionText doesn’t work. ActiveStorage is a hard dependency of ActionText. This is very not-omakase. So what I ended up doing was:

  1. Add ActiveStorage migrations / tables to the database (although I have no plans on using them)
  2. Use CSS (!!!) to hide the paperclip icon to prevent file uploads within the rich text editor (Trix)

I regretted I chose to use ActionText as well…it just seems that this is very tightly coupled, without the possibility for developer to choose to swap any part of this system: activestorage-actiontext-trix

But ok, I started a new project in 2020 and already ended up with a solution that’s using ActionText, hiding paperclip icon, because Trix has no config options. Basically a legacy from the beginning.

Today I went to Trix repo in search of adding my own file uploading functionality. What I saw was issues more than 3 months old, that no one replied to. Even worse. PRs unanswered. PRs to documentation. That’s the entry-level helping. The easiest and great to boost motivation for new open source contributors! Instead, there are people asking each other “did you solve this eventually?” and stale bot closing down “stale” issues no one replied to.

How can we fix this?

Thanks for reading till the end!

1 Like

Can you explain what you mean by this? Encrypts which name?

I have a sense that “there’s no way to turn this off” most likely isn’t true, but it’s not exactly clear what you’re trying to turn off.

Thanks for replying!

Can you explain what you mean by this? Encrypts which name?

Sorry, my bad. It’s not called “signed global id”, but “secure global id”. If I understand correctly, it’s not possible to read the stored data without going through the rails app? Maybe I’m misunderstanding something.

From here: ActiveStorage::Blob

A blob is a record that contains the metadata about a file and a key for where that file resides on the service.

Ok, so the file is not encrypted, but its filename is obfuscated and is without an extension. That information is stored in your rails database.

there’s no way to turn this off

This would refer to: there’s no configuration that could be used to how the files will be stored. It’s decided and, if you don’t like it you can either monkey patch the (activestorage) gem or use an entirely different solution.

I hope it’s more understandable now what I meant? Thanks!

EDIT: This seems to be a good explanation on how actiontext file uploads work: Disassembling Rails — How does ActionText deal with file upload? | by Stan Lo | Medium

If you want files to be publicly accessible then indexing them should go through your rails application (i.e. list the files and their names), and you can return the service_url ActiveStorage::Blob for a blob for direct download from the hosted service.

1 Like

Rails master has a merged PR that adds proxy functionality to ActiveStorage, which allows files to be cached by your CDN. First access has to go through you rails app, which will stream the file, them the CDN can serve them (I’m using Cloudflare).

I’ve been using rails master on production, and updating weekly, for months now, and haven’t had a single problem. Highly recommend.


That looks great! Thanks, Breno!