How to Exclude PaperTrail Versions from Views in RailsAdmin

I am using RailsAdmin v0.6.8 with PaperTrail for version control.

The list, display, creation and editing of views for each of my has_paper_trail models includes a version attribute. In fact, the create and edit views allow you to add / remove versions, which doesn't really make sense to me. Besides using exclude_fields: versions for each view in each model, is there a global way to do this?

Thank!

+5
source share
3 answers

Method 1

If all models are inherited by an abstract class (for example: "ApplicationRecord"),
you can create a new file (for example:) app/models/concerns/exclude_versions.rb:

module ExcludeVersions
  extend ActiveSupport::Concern

  included do
    rails_admin do
      configure :versions do
        hide
      end
    end
  end

end

:

class ApplicationRecord < ActiveRecord::Base
  self.abstract_class = true
  has_paper_trail

  def self.inherited(subclass)
    subclass.include(ExcludeVersions)
    super
  end
end

2

, config/initializers/rails_admin.rb

  Rails.application.eager_load! if Rails.env.development?

  ActiveRecord::Base.descendants.each do |imodel|
    ### next if ['ApplicationRecord'].include?(imodel.name) ### if all models are inherited an abstract class, please uncomment this line, or some strange error will happen
    config.model "#{imodel.name}" do
      configure :versions do
        hide
      end
    end
  end

: https://github.com/sferik/rails_admin/wiki/Models#configuring-models-all-at-once

+3

rails_admin configuratoin :

config.actions do
  history_index do
    except %w(ModelA ModelB)
  end
end

:

config.actions do
  history_index do
    only %w(ModelA ModelB)
  end
end
0

In the rails_admin initializer, I did the following:

config.model 'DcDiscipline' do
  edit do
    exclude_fields :versions 
  end     
end
0
source

Source: https://habr.com/ru/post/1598834/


All Articles