I'm using RailsAdmin v0.6.8 with PaperTrail for versioning.
The list, show, create and edit views for each of my has_paper_trail Models includes the versions attribute. In fact the create and edit views allow the addition/removal of versions, which doesn't really make sense to me. Other than using exclude_fields :versions for each view on each Model, is there a global way to do this?
Thanks!
If all models are inherited 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
and edit the abstract class like:
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
has_paper_trail
def self.inherited(subclass)
subclass.include(ExcludeVersions)
super
end
end
If all models are not inherited an abstract class, you can just add such code in 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
Reference: https://github.com/sferik/rails_admin/wiki/Models#configuring-models-all-at-once
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With