DEV Community

Dr Nic Williams
Dr Nic Williams

Posted on

What is the ordering of Ruby on Rails controller filters?

Some of my application's controllers are a blend of modules from other people's Rubygems, such as ShopifyApp library. They inject before and after action filters around my actions. Sometimes they abort the request and redirect somewhere else. I wanted to know what filters were being invoked and in what order:

class ProductsController < AuthenticatedController
  def index
    __callbacks[:process_action].map { |c| [c.kind, c.instance_variable_get(:"@key")] }
  end
end
Enter fullscreen mode Exit fullscreen mode

The output was like:

[
  [:around, 82000],
  [:before, :set_shop_host],
  [:before, :redirect_to_splash_page],
  [:before, :set_locale],
  [:after, :set_test_cookie],
  [:before, :verify_authenticity_token],
  [:after, :verify_same_origin_request],
  [:after, :set_esdk_headers],
  [:before, :login_again_if_different_user_or_shop],
  [:around, :activate_shopify_session],
  [:before, :set_shop_origin]
]
Enter fullscreen mode Exit fullscreen mode

Top comments (0)