Integrate ActiveAdmin with Rails

This tutorial will help you integrating ActiveAdmin with Rails 4+ project. ActiveAdmin is open source administrative framework for Ruby on Rails.

active-admin

Source: Github Source Website: ActiveAdmin Website

What is ActiveAdmin?

As described ActiveAdmin is open source administrative framework that can be used with Rails framework. ActiveAdmin is helpful for content management by creating admin users. And giving them access to features to access, modify records. It also gives features to search and sort over database records.

Why ActiveAdmin?

If you are going to create a new web application using Rails framework and you want to design admin side for the application. Then, ActiveAdmin does exactly the same thing. It gives many features out of the box for you application.

How to Integrate with Rails?

1. Add to Gemfile
gem 'activeadmin', github: 'activeadmin'

Adding activeadmin to Gemfile tells Rails project to use this gem (library) for your project.

2. Bundle
bundle install

This will install activeadmin gem on your machine if not already installed. And it will be ready for use with current Rails application

3. Install defaults for Application
rails generate active_admin:install

This will create initializers and app/admin directory as well. This folder contains configuration files that get used by activeadmin. This also sets up routing for you.

It is advised to use device for user management. ActiveAdmin also relies on device gem for admin user management. If you have not added device in your gemfile then it will ask you to add device gem to your Rails application.

4. Migration
rake db:migrate

ActiveAdmin creates Admin user to begin with. rake db:migrate creates the tables needed for activeadmin to function.

5. Test

Migration also creates a dummy admin user to begin with.

Email: [email protected] Password: password

You can test if admin framework is properly integrated from url:

http://127.0.0.1:3000/admin

Use the credentials give above to enter.

6. Register a model

You can register your model to be used with activeadmin by following command:

rails generate active_admin:resource

e.g.

rails generate active_admin:resource Gadget

This will integrate the Gadget model with activeadmin and it will start showing up in admin dashboard, where you can search, edit, update.

7. CRUD with activeadmin

ActiveAdmin provides a way to create new records for registered models. When you open particular models page, it shows records in the table and gives filtering functionality. It also provides create, update features.

You can test this with the existing model that gets created during installation:

http://localhost:3000/admin/admin_users

This will show 1 record that you are logged in with. Option to view, edit and delete is provided.

8. Setting attributes for update

You need to set attributes to be permitted for update when you register a new resource with admin. This can be done in app/admin/model.rb file.

permit_params :list, :of, :attributes, :on, :model

The attributes that you specify here are permitted for update through admin dashboard.

Hope you found this helpful integrating ActiveAdmin with your Rails Project. Feel free to ask questions through comments if you face any difficulty.

-->