Reputation: 125
I've:
Set up a rails project
Added Active Admin.
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"
Upvotes: 7
Views: 3366
Reputation: 118
I run into the same issue, and found out that this answer fixed the issue for me: https://stackoverflow.com/a/72005456/583560
[...]adding an initializer with the following worked (Rails 6.0.4.7):
Rails.application.reloader.to_prepare do ActiveStorage::Blob end
Upvotes: 6