Using Administrate and acts-as-taggable-on gems in a Rails app

Isabel Teh
Sep 7, 2018 · 2 min read

Thoughtbot’s Administrate is a library for Rails apps that automatically generates admin dashboards. Recently in a project I was working on, I attempted to add my Tags model into the already up and running Administrate dashboard so I could manage tags in the admin panel. Unfortunately, I couldn’t for the life of me figure out the right way to do this as we were using a tagging plugin called acts-as-taggable-on to add tags to the existing models.

Fast-forward after hours of Googling and searching for answers, I came across a blog post written almost entirely in Japanese (save the code parts, thank God) that mentioned the two gems in question. After semi-blindly following the instructions, it happened to be exactly what I needed. Realising then that most English readers (or non-Japanese readers) would most likely overlook that blog post and spend hours searching like me, I decided to share the steps here (with a few tweaks).


Disclaimer: This post assumes that you have set up the Rails app with Administrate and acts-as-taggable-on as we won’t be going through the setup. Also, note that each tag here has_many taggings and taggings belong_totags.


To start off, you’ll need to generate the dashboards for tags and taggings. To do this, run these commands in your terminal. This will generate the dashboard and controller files in the respective folders.

$ bundle exec rails generate administrate:dashboard ActsAsTaggableOn::Tag
$ bundle exec rails generate administrate:dashboard ActsAsTaggableOn::Tagging

Then you want to go ahead create new folders under app/dashboards and app/controllers called acts_as_taggable_on and move the files into that folder (you can do this either manually or with these commands).

$ mkdir app/dashboards/acts_as_taggable_on
$ mkdir app/controllers/admin/acts_as_taggable_on
$ mv app/dashboards/tag_dashboard.rb app/dashboards/acts_as_taggable_on/
$ mv app/controllers/admin/tags_controller.rb app/controllers/admin/acts_as_taggable_on/
$ mv app/dashboards/tagging_dashboard.rb app/dashboards/acts_as_taggable_on/
$ mv app/controllers/admin/taggings_controller.rb app/controllers/admin/acts_as_taggable_on/

Once that is done, simply configure your routes like so.

namespace :admin do
#...

namespace :acts_as_taggable_on do
resources :tags
resources :taggings
end
end

Now, it’s recommended to change the compact definitions (e.g.class ActsAsTaggableOn::TagDashboard) in favour of nested modules. So let’s edit the generated files to look like this.

app/dashboards/acts_as_taggable_on/tag_dashboard.rb

module ActsAsTaggableOn
class TagDashboard < Administrate::BaseDashboard
#...

# Overwrite this method to customize ...
#
end
end

app/dashboards/acts_as_taggable_on/tagging_dashboard.rb

module ActsAsTaggableOn
class TaggingDashboard < Administrate::BaseDashboard
#...
end
end

app/controllers/admin/acts_as_taggable_on/tags_controller.rb

module Admin
module ActsAsTaggableOn
class TagsController < Admin::ApplicationController
# ...
end
end
end

app/controllers/admin/acts_as_taggable_on/taggings_controller.rb

module Admin
module ActsAsTaggableOn
class TaggingsController < Admin::ApplicationController
# ...
end
end
end

And voilà, you’re done. You should now see the resource in the navigation sidebar and be able to manage the resource in the admin panel. You might also want to go ahead and clean up/configure your dashboard as per your requirements.

I hope this helps someone out there and happy coding!

Upstack Studio

Behind the scenes of Upstack Studio. We share everything we know about technology and business.

Isabel Teh

Written by

Psychology graduate turned programmer. Currently working with React Native and Ruby on Rails.

Upstack Studio

Behind the scenes of Upstack Studio. We share everything we know about technology and business.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade