samedi 25 janvier 2020

How to include a mixin/module in ALL ActiveAdmin controllers?

I have written a module - JsonLog - that uses the append_info_to_payload hook provided by Rails to add some custom metrics to the logging instrumentation. I want to include/mixin this module in all the controllers of ActiveAdmin.

I've tried the following, and it works...

ActiveAdmin.register MyModel do
  controller do
    include JsonLog
  end
end

...but this will force to me write the boilerplate code in every single model/controller that I'm registered with ActiveAdmin. How do I do this in one place (and in the process also ensure that this boilerplate is never missed out)?

Aucun commentaire:

Enregistrer un commentaire