Fixing Blank Content in ActiveAdmin with Quill Editor and ActionText
The Problem: Disappearing Content
Here's how I discovered this bug: I had just launched the blog feature for Career Helix and published my very first blog post. I was excited to share it, promoted it, and moved on to other work.
Almost a week later, I checked the analytics and saw the post had 7 views. Great! People were actually reading it. But when I clicked through to see the post myself, my heart sank.
The entire content was blank. Just a title, metadata, and... nothing.
I immediately went to the ActiveAdmin panel to investigate. When I opened the edit page, the content field was completely empty. What happened?
Then I remembered: I had initially created the post as a draft, written all the content, saved it, and then came back later to change the status from "draft" to "published." That status change must have triggered an update that wiped out all the content.
Seven people had already seen my blank blog post. Embarrassing doesn't begin to describe it.
Worse yet, I realized this could happen again with any blog post edit. This wasn't just a one-time glitch—it was a systematic bug waiting to destroy content.
The Setup
Our Rails 8 application uses:
- ActiveAdmin for the admin panel
- ActionText (
has_rich_text :content) for rich text editing - activeadmin_quill_editor gem for a better editing experience than the default Trix editor
The blog post model looked like this:
And the ActiveAdmin configuration:
Seemed straightforward, right? Wrong.
Initial Investigation
First, I checked if the content actually existed in the database:
rails runner "post = BlogPost.first; puts post.content.body.present?"# => true
The content was there. So why wasn't it showing in the edit form?
I tried the obvious fix—eager loading the ActionText content:
Still blank.
I tried setting the value explicitly in the form:
Nope. Still nothing.
The Root Cause
After some digging, I found the real issue: the activeadmin_quill_editor gem doesn't support ActionText's has_rich_text associations.
Here's why:
- ActionText stores content separately: When you use
has_rich_text :content, Rails stores the actual content in a separateaction_text_rich_textstable with polymorphic associations - Quill expects a string field: The
activeadmin_quill_editorgem expects a simple string or text column, not an ActionText association - The form can't read the association: When the form tries to populate the Quill editor, it's looking for a
contentstring attribute, but instead finds anActionText::RichTextobject that it doesn't know how to handle
Result? Blank field in the editor.
The Solution
The fix comes from the gem's official documentation, specifically this GitHub issue comment.
The solution is to create wrapper methods that act as a bridge between ActionText and the Quill editor.
Step 1: Add Wrapper Methods to Your Model
What this does:
- Getter (
quill_content): Extracts the HTML body from the ActionText object and returns it as a safe HTML string that Quill can read - Setter (
quill_content=): Takes the HTML from the form submission and assigns it to the ActionTextcontentattribute
Step 2: Update ActiveAdmin to Use the Wrapper
Change your ActiveAdmin resource to use quill_content instead of content:
Step 3: Restart Your Server
ActiveAdmin configurations are loaded at startup, so you need to restart your Rails server for the changes to take effect.
Why This Worked
The wrapper methods solve the impedance mismatch between ActionText and Quill:
- On form load:
quill_contentextracts the HTML from ActionText and provides it as a plain string to the Quill editor - On form submit:
quill_content=receives the edited HTML and saves it back to ActionText - ActionText handles the rest: Once the content is assigned via
self.content = value, ActionText takes care of storing it in theaction_text_rich_textstable
The beauty of this approach is that it's completely transparent to the rest of your application. Everywhere else in your code, you still use @blog_post.content as normal.
Conclusion
This was a critical bug that risked losing published content. The fix is straightforward once you understand the incompatibility between activeadmin_quill_editor and ActionText.
If you're using this gem combination, implement the wrapper methods now—before you accidentally save a blank post.