João Ramires
João Ramires

Reputation: 763

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 ?

Upvotes: 0

Views: 1246

Answers (4)

nikos83
nikos83

Reputation: 423

In rails 6 I used

config.excluded_models = %w[ActiveStorage::Blob ActiveStorage::Attachment ActiveStorage::VariantRecord]

Upvotes: 0

abmap
abmap

Reputation: 309

In Rails 6 I do the following

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

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

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

Upvotes: 0

Icaro Rezende
Icaro Rezende

Reputation: 26

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.

Upvotes: 1

Guillermo Siliceo Trueba
Guillermo Siliceo Trueba

Reputation: 4619

You almost got it, it needs to be

config.model 'Blob' do
 visible false
end  

Option b) On the model itself blob.rb

class Blob < ApplicationRecord
  rails_admin do
    visible false
  end
end

Upvotes: 1

Related Questions