http://activeadmin.info/documentation.html
Note that I usually use Devise to authenticate the Active Admin user (which by default is AdminUser), so check that part the gist out first!
First add the gems.
# Gemfile
gem 'activeadmin'
gem 'sass-rails'
gem 'meta_search', '>= 1.1.0.pre'
Install gems.
$ bundle
Run the installer.
$ rails generate active_admin:install
Migrate the database.
$ rake db:migrate
Email settings for production.
# config/environments/production.rb
config.action_mailer.default_url_options = { :host => '<your host>' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:domain => '<your domain>',
:user_name => '<username>',
:password => '<password>',
:authentication => 'plain',
:enable_starttls_auto => true
}
Email settings for development.
# config/environments/development.rb
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :test
Make sure that the necessary resources are precompiled.
# config/environments/production.rb
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
config.assets.precompile += %w( active_admin.css active_admin.js )
config.assets.compile = false
By default (with a default Rails project)
Log in to your new admin interface at /admin
username: [email protected]
password: password
To add your resource to active admin, register them like so.
rails generate active_admin:resource [MyModelName]
Devise can then handle permissions by supplied authentication methods to use in the resouce controller. Like so.
# [model]_controller.rb
class [Model]Controller < ApplicationController
before_filter :authenticate_user!, :except => [:index, :show]
end
https://github.com/gregbell/active_admin/wiki/Your-First-Admin-Resource%3A-AdminUser
First add the admin model, by standard AdminUser, as a resouce.
rails generate active_admin:resource AdminUser
Simplify the creation of new administrators. Just enter their email and the password gets sent to them.
# app/admin/admin_users.rb
ActiveAdmin.register AdminUser do
#...
form do |f|
f.inputs "Admin Details" do
f.input :email
end
f.buttons
end
end
Send a recovery password upon AdminUser creation, and when creating setting of password is optional.
# app/models/admin_user.rb
after_create { |admin| admin.send_reset_password_instructions }
def password_required?
new_record? ? false : super
end
To stop from deleting the last AdminUser from the system, add this.
before_destroy :raise_if_last
def raise_if_last
if AdminUser.count < 2
raise "Can't delete last admin user"
end
end
Resource interface example.
ActiveAdmin.register User do
form do |f|
f.inputs "Details" do
f.input :email
f.input :role, :as => :select, :multiple => false, :required => true, :collection => User::ROLES
end
f.buttons
end
index do
column :id
column :email
column :role
column "Joined", :created_at
column :last_sign_in_at
default_actions
end
end
https://github.com/gregbell/active_admin/wiki/How-to-work-with-cancan
It would be nice if you could add something about how to configure password mails with active admin.
Like:
and