Search code examples
ruby-on-railsrubygemsmonkeypatching

Monkey patch ActiveAdmin class from engine


I have an engine that will be installed over an application that uses Active Admin...

After install Active Admin, I need to run my engine installer. This will create a file monkey patching an Active Admin class.

The file looks like this...

module ActiveAdmin
  module Devise
    # things I need to add...
  end
end

So, the question is: where I need to put this file and why?


Solution

  • I used the Railtie's initializer method.

    my_engine/lib/admin_invitable/engine.rb

    module MyEngine
      class Engine < ::Rails::Engine
        isolate_namespace MyEngine
        initializer "ativeadmin_invitable_patch" do |app|
          require_relative "activeadmin_invitable_patch"
        end
      end
    end
    

    my_engine/lib/admin_invitable/activeadmin_invitable_patch.rb

    module ActiveAdmin
      module Devise
        # bla bla
      end
    end