Reputation: 6793
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)?
Upvotes: 3
Views: 1633
Reputation: 2978
Don't be shy to read the source. There is an ActiveAdmin::BaseController
that inherits from InheritedResources::Base
that in turn inherits from your ApplicationController
. If you really need to specifically modify ActiveAdmin::BaseController
then try this in config/initializers/active_admin.rb
:
ActiveAdmin::BaseController.class_eval do
include JsonLog
end
Upvotes: 2