How to Create an Admin Dashboard with Rails Activeadmin
Do you have an application that needs administrative activities from specific authenticated users? active admin is what you need. Long before active admin, developers had to go through the stress of not just building applications but also user admin dashboards through which content could be added or manipulated. Some months ago, I built an eCommerce website using rails and after implementing active admin, I realized I saved up to 30% development time compared to when I did not use active admin. Simple to implement but powerful features is how I describe activeadmin.
I am going to take you through a step by step explanation on how to setup activeadmin in any rails application.
Activeadmin is an administration framework for Ruby on Rails. Opppps!! did I just use a complicated word? Nothing to be scared of, It simply means, activeadmin provides you with a fully functional administrative dashboard in your rails administration. Enough with the praises, let’s give this app an administrative dashboard.
Step-One: Setting up a rails application
Create a rails application using the rails new command in your terminal.
Wait until the command is fully carried out. Open the application folder that gets created (activeadmin-application) in your preferred text editor. Go to the ruby gem main site, make a copy of the gems activeadmin and device. If you are wondering why we need device, It is a dependency of activeadmin that is used to create and authenticate admin users. Paste the two gems in your Gemfile and run bundle install.
Make sure to set a root route for the application and a controller to which the route maps to. This is to avoid routing errors after running the development server. To save time, we will not do that in this article but just to hint you a little bit, generate a controller with an action, and use the route of the action as the root route defined in your route file. In case you generated an articles controller with an index action, this is how you would define the root route.
Step-Two: Creating models
For this example, we will use two models, article and comment in a many-to-one relationship. This means that an article can have many comments while a comment can only belong to an article.