duykhoa
duykhoa

Reputation: 2302

Override html in active_admin gem

I wanna override html code when working with active_admin gem in Rails; because the nav-bar and many elements in these gem's views are different with my views (other pages). I hope that has a way to change html code without changing css manually! Thanks

Upvotes: 2

Views: 1046

Answers (1)

Fivell
Fivell

Reputation: 11929

It is not very easy , activeadmin use DSL for building html (called "Arbre") You have to monkey patch every page class, also , it may prevent customizing of css too.

For example to move sidebar to left, create initializer with next patch.

class ActiveAdmin::Views::Pages::Base < Arbre::HTML::Document

     def build_page_content
          build_flash_messages
          div :id => "active_admin_content", :class => (skip_sidebar? ? "without_sidebar" : "with_sidebar") do

            build_sidebar unless skip_sidebar?
            build_main_content_wrapper
          end
    end
end

default method was

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

The full list of classes used for rendering can be found here , so some of them you need to patch. https://github.com/gregbell/active_admin/tree/master/lib/active_admin/views

Be ready for a big piece of work.

UPD. Gem for changing activeadmin sidebar position

https://github.com/Fivell/active_admin_sidebar

Upvotes: 3

Related Questions