Reputation: 63
I have the following concern:
./app/controllers/concerns/activity_helper.rb
module ActivityHelper
extend ActiveSupport::Concern
included do
before_action :my_method, except: %i[update destroy]
end
def my_method
...
end
end
Currently i am including this concern in several Active Admin page controllers manually like so:
./app/admin/dashboard.rb
controller do
include ActivityHelper
end
I already tried the following but it does not work without giving any error:
module ActiveAdminControllerConcern
extend ActiveSupport::Concern
included do
controller do
include ActivityHelper
end
end
end
def add_active_admin_controller_concern
ActiveAdmin::ResourceDSL.send(:include, ActiveAdminControllerConcern)
end
ActiveAdmin.setup do |config|
config.before_action :add_active_admin_controller_concern
end
How to automatically include only the module ActivityHelper in all Active Admin page controllers?
Upvotes: 1
Views: 486
Reputation: 63
You don't need the file ./app/controllers/concerns/active_admin_controller_concern.rb
Just add the following line at the end of the file ./config/initializers/active_admin.rb
ActiveSupport.on_load(:active_admin_controller) do
include ActivityHelper
end
Upvotes: 0