DEV Community

Dr Nic Williams
Dr Nic Williams

Posted on

2 1

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)

👋 Kindness is contagious

Explore this insightful post in the vibrant DEV Community. Developers from all walks of life are invited to contribute and elevate our shared know-how.

A simple "thank you" could lift spirits—leave your kudos in the comments!

On DEV, passing on wisdom paves our way and unites us. Enjoyed this piece? A brief note of thanks to the writer goes a long way.

Okay