The initial step in adding new administrators to Active Admin is to create an AdminUser record. This can be accomplished by utilizing the AdminUser model's create! method. The following code snippet demonstrates the creation of an AdminUser with the email address "admin@example.com" and the password "password":
AdminUser.create!(:email => 'admin@example.com', :password => 'password', :password_confirmation => 'password')
Alternatively, if the desired behavior is to set the password within the interface instead of sending a reset email, certain modifications can be made. Firstly, the admin_user model should be left at its default settings. Subsequently, navigate to app/admin/admin_users.rb and implement the following code:
ActiveAdmin.register AdminUser do
index do
column :email
column :current_sign_in_at
column :last_sign_in_at
column :sign_in_count
default_actions
end
form do |f|
f.inputs "Admin Details" do
f.input :email
f.input :password
f.input :password_confirmation
end
f.buttons
end
end
For those seeking to create users (devise users, table "users") within the admin panel, the following steps are recommended:
- $ rails generate active_admin:resource user
- app/admin/user.rb:
ActiveAdmin.register User do
permit_params :email, :name, :password, :password_confirmation
index do
column :name
column :email
actions
end
form do |f|
f.inputs 'User' do
f.input :name
f.input :email
f.input :password
f.input :password_confirmation
end
f.actions
end
end