ruby-on-rails – 自定义activeadmin的布局(组件)

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 自定义activeadmin的布局(组件)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Activeadmin布局不仅仅是一个文件,它是一个组件集合.

如何使用activeadmin覆盖某些组件,如徽标,导航.

解决方法

activeadmin布局组件非常容易定制.您需要做什么:只需定义一个打开ActiveAdmin :: View的模块.

您可以在初始化程序或管理目录中具有custom_activeadmin_components.rb,您可以在其中定义所有activeadmin资源.我更喜欢将它放在activeadmin资源所在的目录中.然后覆盖您想要的任何模块:

这是一个示例:

module ActiveAdmin
  module Views
    class Header < Component
      def build(namespace,menu)
        super(:id => "header")

        @namespace = namespace
        @menu = menu
        @utility_menu = @namespace.fetch_menu(:utility_navigation)

        build_site_title
        build_global_navigation
        build_utility_navigation
        #you can add any other component here in header section 
      end

      def build_site_title
        render "admin/parts/logo"
      end

      def build_global_navigation
        render "admin/parts/main_nav"
      end

      def build_utility_navigation
        render 'admin/parts/language_options'
        insert_tag view_factory.global_navigation,@utility_menu,:id => "utility_nav",:class => 'header-item tabs'
        render 'admin/parts/branch_in_header'
      end
    end

    module Pages
      class Base
        def build_page_content
          build_flash_messages

          div :id => :wizard_progress_bar do
            render 'admin/parts/wizard_progress_bar'
          end

          div :id => "active_admin_content",:class => (skip_sidebar? ? "without_sidebar" : "with_sidebar") do
            build_main_content_wrapper
            build_sidebar unless skip_sidebar?
          end
        end
      end
    end  
  end
end

猜你在找的Ruby相关文章