Rails 在尝试使用 activeadmin 和主动存储时找不到 ActiveStorage::Blob 关联的有效模型
我:
设置了一个铁路项目
添加了Active Admin。
设置活动存储,更新配置以在本地连接并执行:
bin/rails active_storage:安装
bin/rails db:迁移
,然后尝试设置一个非常简单的模型文档
,其中包含一个文件:
class Document < ApplicationRecord
has_one_attached :file
end
以及最简单的主动管理页面:
ActiveAdmin.register Document do
permit_params :name, :type, :file
end
我在尝试尝试时会遇到以下错误访问页面:
Rails找不到Activestorage :: Blob关联的有效模型。 请在协会声明中提供:class_name选项。 如果已经提供:class_name,请确保它是 Activerecord ::基本子类。
我不确定出了什么问题。从文档看,一切都应该在迁移之后工作,并将该行添加到模型中。
Ruby版本:“ 3.1.1”
铁轨版本:“ 7.0.2”
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"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题,并发现这个答案为我解决了问题:
https://stackoverflow.com/a/72005456/583560
I run into the same issue, and found out that this answer fixed the issue for me:
https://stackoverflow.com/a/72005456/583560