Search code examples
ruby-on-railsrails-adminrails-activestorage

Rails Admin: How to Hide Active Storage models?


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:

enter image description here

And its models in Dashboard:

enter image description here

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]

But since i'm using attachments in Notebook it complains:

enter image description here

Then I tried to just hide:

config.model 'ActiveStorage' do
 list do
  visible false
 end
 navigation do
  visible false
 end
end  

Also with the models directly

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  

As we can do with ActiveRecord as shown in Creating a Custom Field Factory ?


Solution

  • In your rails_admin.rb add the following:

    config.model 'ActiveStorage::Blob' do
      visible false
    end
    

    since the Blob class comes from ActiveStorage.

    The same applies for the Attachment class.