How to Add an Admin Dashboard to a Rails API using the Administrate Gem
Tue, Jan 30, 2018A quick guide on adding an adnmin dashboard to a Rails app using the Administrate gem.
What’s an admin dashboard?
Admin dashboards provide a GUI for your Rails app that allow you to perform CRUD (create, read update, delete) actions on your database.
Admin Dashboards can be a nice alternative to the console, and a great way for endusers to edit records.

Why I Chose the Administrate Gem
After some research, the most discussed gems I noticed were: activeadmin, rails_admin, and administrate. I also found a blog post with the ominous title “Get Rid of Your Admin Gem”… which I took into consideration when making my decision.
The author covers activeadmin & rails_admin specifically, citing the main issues as not following “the rails way” and bloat. This made me think: Something different than MVC (model, view, controller) in my Rails app and a DSL (domain specific language) to learn? Yuck, no thanks!
My thoughts on DSLs & no MVC
But what about administrate? Let’s take a look at their Github readme:
To accomplish these goals, Administrate follows a few guiding principles:
- No DSLs (domain-specific languages)
- Support the simplest use cases, and let the user override defaults with standard tools such as plain Rails controllers and views.
- Break up the library into core components and plugins, so each component stays small and easy to maintain.
Sounds awesome and covers the concerns mentioned above!
Other things that stood out:
- Support for Rails 5 API only apps out of the box. No tweaks like inheriting from
ActionController::Baseinstead of::API. - Quick setup with builtin generators
- We can make use of Devise’s
before_action :authenticate_user, since it follows MVC
It also doesn’t hurt that administrate is created by ThoughtBot, the people behind amazing gems like Factorygirl & Paperclip.
Setting up Administrate
Github: https://github.com/thoughtbot/administrate
Documentation: https://administrate-prototype.herokuapp.com/
The process is covered well in the documentation, so to to avoid reinventing the wheel, I’ll just cover any anomalies here.
Tips
- If you’re getting an error when running the install generator, like
or`derive_class_name': undefined method `class_name' for nil:NilClass (NoMethodError) Did you mean? class_eval`
Make sure that your database associations are all setup properly. I had some questionable associations to adjust. Relevant Github Issue`PG::UndefinedTable: ERROR: relation "users" does not exist (ActiveRecord::StatementInvalid)` - If you’re getting
Unable to autoload constant UserDashboardetc.:
You may need to generate files for additional models manually.
Myuser_dashboard.rbfile was created, but empty? I had to manually run
and add$ rails g administrate:dashboard Userresources :statsto my routes. No big deal!
Note: My user model was created by devise_token_auth gem
Thoughts
Administrate is awesome! Utilizing generators and MVC(huge plus!) makes setup & customization simple & familiar.