A comparison of different admin frameworks for use with Ruby On Rails

(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com

How to build admin interfaces for Ruby On Rails?

This is a great summary:

RailsAdmin started its life as a port of MerbAdmin to Rails 3 and was implemented as a Ruby Summer of Code project by Bogdan Gaza with mentors Erik Michaels-Ober, Yehuda Katz, Luke van der Hoeven, and Rein Henrichs. The project is self described as a Rails engine that provides an easy-to-use interface for managing your data..

Its main features include:

Display database tables
Create new data
Easily update data
Safely delete data
Automatic form validation
Search and filtering
Export data to CSV/JSON/XML (very handy)
Authentication (via Devise)
User action history
RailsAdmin currently supports only ActiveRecord as the ORM. You can see a live demo of RailsAdmin here.

The current master branch of RailsAdmin targets Rails 3.1.x and it’s naturally aware of the asset pipeline introduced there. Installing RailsAdmin is a trivial exercise. Just add these deps to your Gemfile:

gem ‘fastercsv’ # Only required on Ruby 1.8 and below
gem ‘rails_admin’, :git => ‘git://github.com/sferik/rails_admin.git’

Afterwards you should run:

$ bundle install
$ rails g rails_admin:install
$ rake db:migrate

And you’re done. RailsAdmin uses internally the tried and true Devise for admin users authentication. If you’re already using devise – you’re covered, otherwise RailsAdmin will install it for you.

At this point you can boot your development web server (rails s) and visit the url localhost:3000/admin (or whatever port you’re running the dev server on). You’ll be able to create admin accounts and after you log in you’ll be presented by an attractive admin dashboard, that shows you an overview of all the tables in your model.

By default you’ll be able to manage every single model in your app. You’ll have to customize the contents of config/initializers/rails_admin.rb to change that default behavior.

One thing to note is that there are no gem releases of RailsAdmin. It’s still alpha quality software (at least on paper – it’s quite stable actually). I’m generally a bit annoyed to have to track gems from a git repo, but I understand and respect the developer’s decision on the matter. Hopefully we’ll see a stable release of RailsAdmin soon enough and a gem to go with it.

Another thing to keep in mind is the use case for RailsAdmin – it is pretty much an automatic backend, that you’re not supposed to modify a lot. In its spirit it’s very close to what Django’s admin backend is. RailsAdmin is very smart in determining the relations between model and supplying forms and show views that express them properly.

Unfortunately not all relationships are represented correctly and modifying the form builders in RailsAdmin is no walk in the park. Another minor annoyance is that CarrierWave is not supported out of the box so you have to do some manual tinkering in the RailsAdmin initializer to make it work.

Some of the nicer touches in RailsAdmin include basic integration with CKEditor (a rich WYSIWYG editor) and an user action feature, which helps keep track of who did what. I wouldn’t mind seeing some mention of TinyMCE as an alternative to CKEditor in the docs, since it’s considered more robust by many (yours truly included).

The docs themselves are just a big README in the project’s github repo. While they feature most of what you’ll need to know about RailsAdmin, having them organized in a nicer way (something that the guys behind Active Admin have done) wouldn’t hurt.

Active Admin

Active Admin is the other big Rails admin UI framework, developed by Greg Bell. Its official web site describes it like this:

{% blockqoute %} Active Admin is a Ruby on Rails plugin for generating administration style interfaces. It abstracts common business application patterns to make it simple for developers to implement beautiful and elegant interfaces with very little effort. {% endblockquote %}

Active Admin is of course Rails 3.1 ready, plays nice with the asset pipeline and has great documentation on its official web site. There also a very nice introductory screencast by Ryan Bates from RailsCasts.

Getting started with Active Admin is just as easy as getting started with RailsAdmin. You just need to add a dependency to your Gemfile:

gem ‘activeadmin’

And to a few command line incantations afterwards to seal the deal:

$ bundle install
$ rails g active_admin:install
$ rake db:migrate
$ rails s

Fire up your favorite browser and visit localhost:3000/admin. The default username is admin@example.com and the default password is password. You’d probably be surprised to see an empty dashboard and absolutely no models that you can administer. Active Admin takes a totally different approach compared to RailsAdmin. Here nothing happens automatically – you have to customize your dashboard yourself and you have to register the models you’d be administrating with the following command:

$ rails g active_admin:resource ModelName

This will create a file named app/admin/model_name.rb where you can tinker with looks of the resource’s index, form and show view.

And here comes Active Admin’s core feature – it’s immensely easy to customize anything in the Admin UI. The forms used to create and update model records are simple Formtastic forms (the same Formtastic forms you’re probably already using throughout the rest of your apps):

ActiveAdmin.register Post do
form do |f|
f.inputs “Details” do
f.input :title
f.input :published_at, :label => “Publish Post At”
f.input :category
f.inputs “Content” do
f.input :body

Rendering a partial for the form is also supported.