Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customise layout (components ) for activeadmin

Activeadmin layout is not just a file, its a collection of components.

How can I override some of the components like, logo, navigation with activeadmin.

like image 319
Muntasim Avatar asked Jun 07 '13 05:06

Muntasim


1 Answers

The activeadmin layout components are very easy to customize. What you need to do: Just define a module that opens ActiveAdmin::View.

you can have a custom_activeadmin_components.rb in initializers or admin directory where you defined all of your activeadmin resources. I prefer to put it in the directory where your activeadmin resources are. Then override any module you want:

here is a sample:

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
like image 54
Muntasim Avatar answered Oct 11 '22 22:10

Muntasim