我在我的ApplicationController中有一個認證方法,我總是想先運行。我也有一個子控制器中的方法,我想在認證方法之後運行,但在另一個ApplicationController before_actions之前。換句話說,我想這一點:Rails:超類prepend_before_action
ApplicationController
before_action first
before_action third
OtherController < ApplicationController
before_action second
以上引起的才能被調用的方法:first
- >third
- >second
。 但我想要下單:first
- >second
- >third
。
我使用prepend_before_action嘗試,就像這樣:
ApplicationController
prepend_before_action first
before_action third
OtherController < ApplicationController
prepend_before_action second
但是,這會導致它去second
- >first
- >third
。如何獲取訂單first
- >second
- >third
?
不幸的是,我的所有子類我不得不盡管添加此解決方法。我希望有一些方法可以修改ApplicationController來實現結果。 – Robert
如果它在大多數控制器中,則可以在父項中運行:second_action並跳過少數子項。 –