This tutorial will help you integrating ActiveAdmin with Rails 4+ project. ActiveAdmin is open source administrative framework for Ruby on Rails.
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.
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
Adding activeadmin to Gemfile tells Rails project to use this gem (library) for your project.
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
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.
ActiveAdmin creates Admin user to begin with.
rake db:migrate creates the tables needed for activeadmin to function.
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:
Use the credentials give above to enter.
6. Register a model
You can register your model to be used with activeadmin by following command:
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:
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
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.
Subscribe to Ruby in Rails
Get the latest posts delivered right to your inbox