- Enable developers to quickly create good-looking administration interfaces.
- Build a DSL for developers and an interface for businesses.
- Ensure that developers can easily customize every nook and cranny.
The path to success is described step by step
while the troubleshooting and resolution steps you should not need are indented to the right and kept as reference only.
I am applying Active Admin to my ProvisioningEngine Frontend proof of concept, because I want to move some configurations from a figaro based config file to the database, and I want to make sure that only authorized administrators can change those settings. Moreover, Active Admin offers nice tables with pagination, sorting and filtering. And an already present model can be migrated to active Admin simply by a single
rails g command (not part of this blog post).
I am closely following the officially installation documentation on http://activeadmin.info/docs/0-installation.html. However, because I have run into a rails generator bug (falsely reported as activeadmin issue#4295), I had to roll back (git stash) my changes, which in turn did not restore the database (is ignored with git) and that had caused additional challenges. But first things first:
Step 1: install activeadmin
For installation of Active, we need to add following lines to the Gemfile
#Gemfile gem 'devise' gem 'activeadmin', '1.0.0.pre2'
Devise is a requirement, and is not automatically installed as dependency. The activeadmin version statement
'1.0.0.pre2' is important as well: I was running into several additional issues, when I first tried without version statement, and later with
'1.0.0.pre2' worked, apart from issue#4295, but this is an issue that is unlikely to hit.
Then we perform:
Step 2: generate the base admin user model and routing
The next command
rails generate active_admin:install
should add the following files (among others):
and add routes to the existing
Note: it did not work in my case, see activeadmin issue#4295). However, this was caused by following statement at the end of my
# config/routes.rb Rails.application.routes.draw do ...(many statements)... end # Rails.application.routes.draw do
I often insert such comments after
end statements to better see, what this is the end of. In this case, this comment has caused the rails generator to insert ActiveAdmin statments twice, like follows:
Rails.application.routes.draw do devise_for :admin_users, ActiveAdmin::Devise.config ActiveAdmin.routes(self) ...(many statements)... end # Rails.application.routes.draw do devise_for :admin_users, ActiveAdmin::Devise.config ActiveAdmin.routes(self)
It seem to be looking for a pattern similar to
/Rails.application.routes.draw do$/ and inserts the three lines thereafter. It does not recognize that it should ignore the second occurence of the pattern, since it is a comment only.
Okay, I do not recommend adding comments like
# Rails.application.routes.draw do after the
end statment in the
routes.rb file for now.
After rolling back with git stash, removing the empty lines after the end statement and starting from scratch, the problem disappeared. However, through the rollback process, I have introduced (minor) other problems, as we will see.
Step 3: prepare the database and start the Web Server
Now, we migrate our database and start the server:
rake db:migrate rails server
Note: In my case, since I had to roll back and the database changes are ignored and thus not rolled back properly, the
rake db:migrate command did not work anymore: the corresponding object(s) had already been created in the database the first attempt.
To resolve this, I had done it the hard way and removed
db/development.sqlite3 file and tried to
rake db:migrate again. That worked, seemingly.
Then we can visit
http://localhost:3000/admin and log in as the default user (in my case, I was using a cloud9 URL instead, since I recently moved part of my development to that online IDE). The initial credentials are:
- User: firstname.lastname@example.org
- Password: password
I guess, because of the fact that I had to reset the database, I ran into an error “invalid email or password”. In my case, the following workaround has worked fine:
$ rails console AdminUser.create :email => 'email@example.com', :password => 'password', :password_confirmation => 'password'
After successful login, we see following Dashboard:
Finally, ActiveAdmin is installed properly.
I have shown step by step how ActiveAdmin can be installed. If you circumvent all the trip hazards I have run into, it can be done in 30 minutes or less.
In my case, the installation process was very much like trial and error. First, you need to add the ‘devise’ dependency not described in the official installation guide. Then, the right version has to be picked; the pre-release:
'1.0.0.pre2'. Unfortunately I ran into a rails bug, but it is unlikely to run into the same one. Everybody has the right of his own bugs ;-).
The rollback process I was enforced to perform was incomplete, since the database is not saved in the repository. This has caused additional minor problems, but those could be worked around with the help of google and stackoverflow.