Installation
Active Admin is a Ruby Gem.
gem 'activeadmin'
# Plus integrations with:
gem 'devise'
gem 'cancancan'
gem 'draper'
gem 'pundit'More accurately, it's a Rails Engine that can be injected into your existing Ruby on Rails application.
Setting up Active Admin
After installing the gem, you need to run the generator. Here are your options:
If you don't want to use Devise, run it with
--skip-users:shrails g active_admin:install --skip-usersIf you want to customize the name of the generated user class, or if you want to use an existing user class, provide the class name as an argument:
shrails g active_admin:install UserOtherwise, with no arguments we will create an
AdminUserclass to use with Devise:shrails g active_admin:install
The generator adds these core files, among others:
app/admin/dashboard.rbapp/assets/javascripts/active_admin.jsapp/assets/stylesheets/active_admin.scssconfig/initializers/active_admin.rb
Now, migrate and seed your database before starting the server:
rails db:migrate
rails db:seed
rails serverVisit http://localhost:3000/admin and log in as the default user:
- User: admin@example.com
- Password: password
Voila! You're on your brand new Active Admin dashboard.
To register an existing model with Active Admin:
rails generate active_admin:resource PostThis creates a app/admin/post.rb file with some content to start. Preview any changes in your browser.
Upgrading
When upgrading to a new version, it's a good idea to check the CHANGELOG.
To update the assets:
rails generate active_admin:assetsYou should also sync these files with their counterparts in the AA source code:
Along with any template partials you've copied and modified.
Gem compatibility
will_paginate
If you use will_paginate in your app, you need to configure an initializer for Kaminari to avoid conflicts.
# config/initializers/kaminari.rb
Kaminari.configure do |config|
config.page_method_name = :per_page_kaminari
endIf you are also using Draper, you may want to make sure per_page_kaminari is delegated correctly:
Draper::CollectionDecorator.send :delegate, :per_page_kaminarisimple_form
If you're getting the error wrong number of arguments (6 for 4..5), read #2703.
webpacker
You can opt-in to using Webpacker for ActiveAdmin assets as well by updating your configuration to turn on the use_webpacker option, either at installation time or manually.
at active_admin installation:
shrails g active_admin:install --use_webpackermanually:
rubyActiveAdmin.setup do |config| config.use_webpacker = true endAnd run the generator to get default Active Admin assets:
shrails g active_admin:webpacker
vite_rails
To use Active Admin with Vite, make sure the @activeadmin/activeadmin dependency is added to your package.json using e.g. Yarn:
yarn add @activeadmin/activeadmin@^3Then follow the steps outlined in this discussion comment: https://github.com/activeadmin/activeadmin/discussions/7947#discussioncomment-5867902