How can I customize the active admin layout?

后端 未结 5 968
梦如初夏
梦如初夏 2021-01-31 09:42

I need to customize the active admin layout, but how can I do it?

5条回答
  •  攒了一身酷
    2021-01-31 10:34

    The active admin layout is not actually defined as a layout file, but is generated programatically. Placing a custom layout in the layout directory will therefore not actually override the default layout.

    You can, however, monkey-patch or duck-punch the active admin layout methods inside your application.

    The following will add an ie-specific stylesheet to the header:

    module ActiveAdmin
      module Views
        module Pages
          class Base < Arbre::HTML::Document
    
            alias_method :original_build_active_admin_head, :build_active_admin_head unless method_defined?(:original_build_active_admin_head)
    
            def build_active_admin_head
              within @head do
                meta :"http-equiv" => "Content-type", :content => "text/html; charset=utf-8"
                insert_tag Arbre::HTML::Title, [title, active_admin_application.site_title].join(" | ")
                active_admin_application.stylesheets.each do |path|
                  link :href => stylesheet_path(path), :media => "screen", :rel => "stylesheet", :type => "text/css"
                end
                active_admin_application.javascripts.each do |path|
                  script :src => javascript_path(path), :type => "text/javascript"
                end
                text_node csrf_meta_tag
                text_node "".html_safe
              end
            end
    
          end
        end
      end
    end
    

    Clearly an ugly solution.

提交回复
热议问题