自定义activeadmin的布局(组件) [英] Customise layout (components ) for activeadmin
问题描述
Activeadmin布局不仅是文件,而且是组件的集合。
Activeadmin layout is not just a file, its a collection of components.
如何使用activeadmin覆盖某些组件,如徽标,导航。
How can I override some of the components like, logo, navigation with activeadmin.
推荐答案
activeadmin布局组件非常易于定制。您需要做的是:只需定义一个打开ActiveAdmin :: View的模块即可。
The activeadmin layout components are very easy to customize. What you need to do: Just define a module that opens ActiveAdmin::View.
您可以在初始化程序或admin目录中拥有一个custom_activeadmin_components.rb,您可以在其中定义所有的activeadmin资源。我更喜欢将其放在您的activeadmin资源所在的目录中。然后覆盖您想要的任何模块:
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:
下面是一个示例:
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
这篇关于自定义activeadmin的布局(组件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!