Manipulate sidebar position and add collapsible sidebar support for ActiveAdmin 3.x.
Add to your Gemfile:
gem 'active_admin_sidebar'Add to app/assets/stylesheets/active_admin.scss:
@import "active_admin_sidebar";Add to app/assets/javascripts/active_admin.js:
//= require active_admin_sidebar$ npm i @activeadmin-plugins/active_admin_sidebar
Or
$ yarn add @activeadmin-plugins/active_admin_sidebar
Add to app/assets/javascripts/active_admin.js:
import '@activeadmin-plugins/active_admin_sidebar';Add to app/assets/stylesheets/active_admin.scss:
@import '@activeadmin-plugins/active_admin_sidebar';Change sidebar position with before_action:
# app/admin/posts.rb
ActiveAdmin.register Post do
before_action only: [:index] do
left_sidebar!
end
end
# app/admin/comments.rb
ActiveAdmin.register Comment do
before_action do
right_sidebar!
end
endMove sidebar to the left for all resources in config/initializers/active_admin.rb:
ActiveAdmin.setup do |config|
config.before_action do
left_sidebar! if respond_to?(:left_sidebar!)
end
endAdd a toggle button to collapse/expand the sidebar. State is persisted per-resource across page navigations.
# Collapsible sidebar (starts expanded)
left_sidebar!(collapsible: true)
right_sidebar!(collapsible: true)
# Collapsible sidebar (starts collapsed)
left_sidebar!(collapsible: true, start_collapsed: true)
right_sidebar!(collapsible: true, start_collapsed: true)