Rails Admin:如何隐藏 Active Storage 模型? [英] Rails Admin: How to Hide Active Storage models?
问题描述
我正在使用 Active Storage 和 Cloudinary 来存储我的一个模型的一些图像,但是在添加此之后,Active Storage 开始出现在 Rails Admin 中专门用于它的导航选项卡中:
I'm using Active Storage and Cloudinary to store some images of one of my models, but after add this the Active Storage started to appear in Rails Admin in a navigation tab dedicated to it:
及其在仪表板中的模型:
And its models in Dashboard:
我想删除两者.我尝试了这些事情但没有成功:
I would to like to remove both. I tried these things without sucess:
首先尝试仅声明我想要出现的模型
Starting by trying to declare only the models I want to be present
config.included_models = [User, Notebook, Tag, Category, Part]
但由于我在 Notebook 中使用附件,它会抱怨:
But since i'm using attachments in Notebook it complains:
然后我试着隐藏起来:
config.model 'ActiveStorage' do
list do
visible false
end
navigation do
visible false
end
end
也可以直接使用模型
config.model 'Attachment' do
list do
visible false
end
navigation do
visible false
end
end
config.model 'Blob' do
list do
visible false
end
navigation do
visible false
end
end
或者也许可以做一些类似的分解
Or maybe it's possible to do something factoring like
ActiveStorage::Base.descendants.each do |imodel|
config.model "#{imodel.name}" do
visible false
end
end
正如我们对 ActiveRecord 所做的那样,如 创建自定义字段工厂 ?
As we can do with ActiveRecord as shown in Creating a Custom Field Factory ?
推荐答案
在您的 rails_admin.rb
中添加以下内容:
In your rails_admin.rb
add the following:
config.model 'ActiveStorage::Blob' do
visible false
end
因为 Blob 类来自 ActiveStorage.
since the Blob class comes from ActiveStorage.
这同样适用于附件类.
这篇关于Rails Admin:如何隐藏 Active Storage 模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!