简体   繁体   中英

Extending Active Admin views in Rails Engine

I've got my Active Admin gem installed in my main app and a mountable engine set up in an "engines" directory I have just created.

I would like to tweak my main app's ActiveAdmin views in my engine so I would be able to add specific links and stuff.

My engine has its own namespace (let's call it MyOwnEngine for simplicity's sake).

I have created a "activeadmin_components.rb" file in my engine's "lib/admin" directory and I have added this:

module MyOwnEngine
    module ActiveAdmin
        module Views
           class Header < ::ActiveAdmin::Component

           def build(namespace, menu)
               super(:id => "header")
               # stuff is done here...nothing that matters, really...
               build_site_title
           end

           def build_site_title
                render "admin/parts/myenginespecificpart" 
           end
        end
    end
end

This lives within the MyOwnEngine namespace but is never displayed, these customizations don't overwrite those written in the main app

If I remove the namespace (the module MyOwnEngine part), then the customizations written in my engine overwrite those of my main app.

if I hit http://whatever/app , I'd like the Active Admin views of my app displayed and if I hit http://whatever/engine , I'd like to have the Active Admin views of my app + the customizations I have done in my engine but I can't.

I know it must be a namespace-related issue and it must be trivial but I can't figure out what it is at the moment.

Any help is appreciated. Thanks.

what you can do is something like this:

require "active_admin/views/header"
module ActiveAdmin
  module Views
    class Header < ::ActiveAdmin::Component

      def build(namespace, menu)
        super(:id => "header")

        if namespace.name == "namespace to hack"
          # stuff is done here...nothing that matters, really...
          build_my_site_title
        else
          @namespace = namespace
          @menu = menu
          @utility_menu = @namespace.fetch_menu(:utility_navigation)

          build_site_title
          build_global_navigation
          build_utility_navigation
        end
      end

      def build_my_site_title
        render "admin/parts/myenginespecificpart"
      end
    end
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM