在 active admin on rails 5 中有条件地删除 header
Remove header conditionnally in active admin on rails5
我需要将我的活动管理页面嵌入到 parent 应用程序中。
活动管理页面将显示在 iframe 中,如果 url 查询参数 embedded=true,我需要删除默认索引、显示和编辑页面上的 header 和页脚。
我在我的活动管理页面中这样做:
ActiveAdmin.register Followup, as: 'Followup_affectation' do
controller do
def setLayout
if params['embedded'] == 'true'
@layout = false
else
@layout = 'active_admin'
end
end
end
并且在某些自定义操作中
render template: "admin/followups/mytemplate.html.haml", layout: @layout
但我想为索引做这件事。
我试过了
def index
render :index, layout: @layout
end
和
def index
super
render :index, layout: @layout
end
我的索引定义真的很经典:
index do
id_column
column :step
column :cycle
column :tag_rfid
column :quoteline
column :product_name
column :location
column :active
actions
end
在此先感谢您的帮助
我终于找到了解决办法。
1 - 在 app/admin/
中创建 header.rb
module ActiveAdmin
module Views
class Header < Component
def build(namespace, menu)
super(id: "header")
#add a class hide wich diplay none on the menu
if params['embedded'] == 'true'
super(class: "hide")
end
@namespace = namespace
@menu = menu
@utility_menu = @namespace.fetch_menu(:utility_navigation)
build_site_title
build_global_navigation
build_utility_navigation
end
def build_site_title
insert_tag view_factory.site_title, @namespace
end
def build_global_navigation
#do not insert tag if params embedded is true
insert_tag view_factory.global_navigation, @menu, class: 'header-item tabs' unless params['embedded'] == 'true'
end
def build_utility_navigation
insert_tag view_factory.utility_navigation, @utility_menu, id: "utility_nav", class: 'header-item tabs'
end
end
end
end
我需要将我的活动管理页面嵌入到 parent 应用程序中。 活动管理页面将显示在 iframe 中,如果 url 查询参数 embedded=true,我需要删除默认索引、显示和编辑页面上的 header 和页脚。
我在我的活动管理页面中这样做:
ActiveAdmin.register Followup, as: 'Followup_affectation' do
controller do
def setLayout
if params['embedded'] == 'true'
@layout = false
else
@layout = 'active_admin'
end
end
end
并且在某些自定义操作中
render template: "admin/followups/mytemplate.html.haml", layout: @layout
但我想为索引做这件事。
我试过了
def index
render :index, layout: @layout
end
和
def index
super
render :index, layout: @layout
end
我的索引定义真的很经典:
index do
id_column
column :step
column :cycle
column :tag_rfid
column :quoteline
column :product_name
column :location
column :active
actions
end
在此先感谢您的帮助
我终于找到了解决办法。 1 - 在 app/admin/
中创建 header.rbmodule ActiveAdmin
module Views
class Header < Component
def build(namespace, menu)
super(id: "header")
#add a class hide wich diplay none on the menu
if params['embedded'] == 'true'
super(class: "hide")
end
@namespace = namespace
@menu = menu
@utility_menu = @namespace.fetch_menu(:utility_navigation)
build_site_title
build_global_navigation
build_utility_navigation
end
def build_site_title
insert_tag view_factory.site_title, @namespace
end
def build_global_navigation
#do not insert tag if params embedded is true
insert_tag view_factory.global_navigation, @menu, class: 'header-item tabs' unless params['embedded'] == 'true'
end
def build_utility_navigation
insert_tag view_factory.utility_navigation, @utility_menu, id: "utility_nav", class: 'header-item tabs'
end
end
end
end