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
RailsAdmin::ApplicationController.class_eval do skip_after_filter :intercom_rails_auto_include end
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!