Rails: prepend_before_action in superclass

I have an authentication method in my ApplicationController that I always want to run first. I also have a method in the subcontroller that I want to run after the authentication method, but before another ApplicationController before_actions. In other words, I want this:

ApplicationController
before_action first
before_action third

OtherController < ApplicationController
before_action second

The above methods are called in the order: firstthirdsecond. But I want the order to be as follows: firstsecondthird.

I tried using prepend_before_action, for example:

ApplicationController
prepend_before_action first
before_action third

OtherController < ApplicationController
prepend_before_action second

But it makes him go secondfirstthird.

How to get order firstsecondthird?

+4
2

prepend_before_action :

class ApplicationController < ActionController::Base
  before_action :first
  before_action :third
end

class OtherController < ApplicationController
  prepend_before_action :third, :second
end
+7

, :

class ApplicationController < ActionController::Base
  before_action :first
  before_action :third
end

class OtherController < ApplicationController
  skip_before_action :third
  before_action :second
  before_action :third
end
+1

Source: https://habr.com/ru/post/1629928/