Adding skip_after_filter to Rails Admin

How I added a skip_after_filter to rails_admin, which is something I recently had to do to extend the functionality of Rails Admin

Recently I had call to want to run skip_after_filter on all Rails Admin Controllers. My specific use case was we are using a gem from Intercom which displays their chat box on each page, and I didn’t want it appearing inside of our admin views.

I am not the only one

Wanting to hide intercom from rails_admin is going to be a pretty niche thing to want to do, so I started searching for the more general case of adding anything with a skip_**_filter to Rails Admin.

After some searching I was not the only one looking at how we can do this, unfortunately although there were plenty of questions, there were few answers.

I think there are two reasons why there aren’t many answers to these questions.

  • This isn’t a particularly common thing to need to do
  • The solution isn’t a pretty one

Can you say, Monkey Patch?

Yup, unfortunately we need to monkey patch (something I hate doing) Rails Admin in order to ensure that we can set skip_after_filter.

RailsAdmin::ApplicationController.class_eval do
  	skip_after_filter :intercom_rails_auto_include

I decided to do this inside config/initializers/rails_admin.rb because I know at the point of setting configutations we must have access to RailsAdmin.

This isn’t pretty, but it works!

Recent posts View all


How to ignore Bullet in RSpec tests

Using Bullet during a test can pick up mistakes but also has false negatives; here is an easy way to ignore them


How we used Nokogiri to fix a sizing issue in YouTube's oEmbed

At some point, one of our calls to YouTube's oEmbed endpoint was returning videos way too small; we fixed in in our Rails application by using Nokogiri