'Rails couldn't find a valid model for ActiveStorage::Blob association, while trying to use activeadmin and active storage

I've:

  1. Set up a rails project

  2. Added Active Admin.

  3. Set up Active Storage, updating the configuration to connect locally and doing:

    bin/rails active_storage:install
    bin/rails db:migrate

Then when trying to set up a very simple model Document with a file attached:

class Document < ApplicationRecord
    has_one_attached :file
end

And the most simple Active Admin page possible for it:

ActiveAdmin.register Document do
  permit_params :name, :type, :file
end

I'm getting the following error when trying to access the page:

Rails couldn't find a valid model for ActiveStorage::Blob association. Please provide the :class_name option on the association declaration. If :class_name is already provided, make sure it's an ActiveRecord::Base subclass.

I'm unsure what is going wrong. It seems from the docs everything should work after the migration and adding that line to the model.

Ruby version: "3.1.1"
Rails version: "7.0.2"



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source