根据角色自定义 ActiveAdmin 页面
Customize ActiveAdmin Page based on Roles
我们如何根据不同用户的角色自定义 ActiveAdmin 页面:
ActiveAdmin.register_page 'Dashboard' do
content title: 'Admin Content' do
# show this only to admins
end
content title: 'Reviewer Content' do
# show this only to reviewers
end
end
在尝试了几个复杂的事情之后,解决方案很简单:
ActiveAdmin.register_page 'Dashboard' do
menu priority: 1, label: proc { I18n.t('active_admin.dashboard') }
content title: proc { I18n.t('active_admin.dashboard') } do
render partial: current_user.admin? ? 'admin_dashboard' : 'content_dashboard'
end
end
然后您可以根据角色渲染这些部分。
我们如何根据不同用户的角色自定义 ActiveAdmin 页面:
ActiveAdmin.register_page 'Dashboard' do
content title: 'Admin Content' do
# show this only to admins
end
content title: 'Reviewer Content' do
# show this only to reviewers
end
end
在尝试了几个复杂的事情之后,解决方案很简单:
ActiveAdmin.register_page 'Dashboard' do
menu priority: 1, label: proc { I18n.t('active_admin.dashboard') }
content title: proc { I18n.t('active_admin.dashboard') } do
render partial: current_user.admin? ? 'admin_dashboard' : 'content_dashboard'
end
end
然后您可以根据角色渲染这些部分。