Rob*_*ert 5 controller ruby-on-rails before-filter operator-precedence
我在我的ApplicationController中有一个我总是想先运行的身份验证方法.我在子控制器中也有一个方法,我希望在身份验证方法之后运行,但在其他ApplicationController before_actions之前运行.换句话说,我想要这个:
ApplicationController
before_action first
before_action third
OtherController < ApplicationController
before_action second
Run Code Online (Sandbox Code Playgroud)
以上原因导致按以下顺序调用方法:first- > third- > second.但是我想要命令:first- > second- > third.
我尝试过使用prepend_before_action,如下所示:
ApplicationController
prepend_before_action first
before_action third
OtherController < ApplicationController
prepend_before_action second
Run Code Online (Sandbox Code Playgroud)
但这会导致它second- > first- > third.
如何获得订单first- > second- > third?
你可以这样使用prepend_before_action:
class ApplicationController < ActionController::Base
before_action :first
before_action :third
end
class OtherController < ApplicationController
prepend_before_action :third, :second
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4240 次 |
| 最近记录: |