CAUTION: Sorry, this gem is not maintained now. I'm looking for maintainer has motivation for apps using ActiveAdmin. Please somebody help me. See more
Role based authorization with CanCanCan for Active Admin
Add this line to your application's Gemfile:
gem 'active_admin_role'
And run bundle
- rails (>= 5.0.0)
- activeadmin (>= 1.2.0)
- cancancan (>= 1.15.0)
https://github.com/activeadmin-plugins/active_admin_role_sample
- Run this command after
rails generate active_admin:install
:
$ bin/rails generate active_admin_role:install
create config/initializers/active_admin_role.rb
insert app/models/admin_user.rb
create db/migrate/20161128090641_add_role_to_admin_users.rb
create db/migrate/20161128090642_create_active_admin_managed_resources.rb
create db/migrate/20161128090643_create_active_admin_permissions.rb
create app/models/ability.rb
gsub config/initializers/active_admin.rb
create app/admin/permissions.rb
insert app/admin/admin_users.rb
$ bin/rails db:migrate
-
You have to login as admin after migration.
-
You have to Reload permissions.
- Edit permissions however you like.
- Of course, you can edit AdminUser's roles.
ActiveAdminRole.configure do |config|
# [Required:Hash]
# == Role | default: { guest: 0, support: 1, staff: 2, manager: 3, admin: 99 }
config.roles = { guest: 0, support: 1, staff: 2, manager: 3, admin: 99 }
# [Optional:Array]
# == Special roles which don't need to manage on database
config.super_user_roles = [:admin]
config.guest_user_roles = [:guest]
# [Optional:String]
# == User class name | default: 'AdminUser'
config.user_class_name = "AdminUser"
# [Optional:Symbol]
# == Default permission | default: :cannot
config.default_state = :cannot
end