- Read Tutorial
With our admin dashboard built let's take a tour of the Administrate dashboard. If we login as an admin user and navigate to /admin
we'll see the dashboard page:
From this page we can see the list of models on the left and by default it's showing the data from the users
table. Also notice how the gem works nicely with single table inheritance and separates our User
from our STI AdminUser
. This is a great feature because it gives admins different interfaces for each type. This will help prevent a regular user accidentally being assigned as a n admin user.
Model Page in Administrate Dashboard
Here in the Topic
model page we can see a list of all topics
in the database, along with a few of their associated attributes, such as their title
and when they were created. It's also easy to search through a database in Administrate, as shown here if we enter in the value 97
into the search bar.
While similar to other gems, such as Rail Admin or ActiveAdmin, Administrate has one feature I absolutely love. Notice that whenever it has a parent model, such as Topic
, it automatically lists out the number of child records that it's associated with? Here you can see that the topic My Title 99
shows a count of 50 posts
. This is a very helpful way of quickly tracking which topics have the most posts.
In addition to search and pagination, the Administrate dashboard also allows you to sort columns, which is a handy feature. Here I'm sorting via Title
.
Adding Records in Administrate
Sometimes admins will need to add records to the database manually, such as creating an AdminUser
. The site admins will now be able to do this on the AdminUser
page in the dashboard. This is a much better user experience than having to create or update a user status via the terminal.
You may notice that if you try to add an AdminUser
right now you'll get an error saying password
can't be blank. This is because Administrate is simply matching the field names in the database. In the next guide we'll walk through how to customize forms in the dashboard to accomplish what we need.
Editing Records in Administrate
Opening up the Post
model page you'll see that we have the ability to edit posts
. This includes some nice built in functionality that enables us to edit not only the content, but also the Topic
and User
that the post is associated with.
Deleting Records in Administrate
Lastly for this tour, you can also delete records from the database using the Destroy
link next to the record you want to remove.
After clicking the confirmation box Administrate will remove the item from the database and update the page.
Summary
Overall I'm a huge fan of the Administrate gem. It's more lightweight than a few of the other dashboards out there, however it's more flexible with how it can be customized. It's also less resource intensive. Gems such as Rails Admin and ActiveAdmin are essentially apps to themselves, so they can cause poor performance for an app, in addition to being difficult to customize. I highly recommend Administrate as an alternative admin dashboard in Rails.
What's Next?
As mentioned earlier, next we'll walk through how to update the AdminUser
form in the admin dashboard so that users can be created via the interface.