before_filter 语法,当你想“除外"时控制器“abc" [英] before_filter syntax when you want to "except" controller "abc"
问题描述
在 Rails 中,当您想排除"控制器abc"时,before_filter 语法是什么.
In Rails what is the before_filter syntax when you want to "except" controller "abc".
例如,在 application_controller 中如果我想说:
Example, in the application_controller if I want to say:
before_filter :login_required :except => ["-name of controller-"]
背景 - 只需要在整个应用程序中进行基本身份验证,除了实际处理用户身份验证的控制器......
Background - Just wanted basic authentication across the whole app except the controller that actually handles getting a user authenticated....
推荐答案
您可以在控制器中不应该执行 before_filter
的地方放置以下行:
You can put the following line in the controller where the before_filter
should not be executed:
skip_before_filter :login_required
您甚至可以使用 :only
和 :except
选项指定忽略 before_filter
的方法:
You can even specifiy the methods where the before_filter
is ignored with :only
and :except
options:
skip_before_filter :login_required, :only => [:login]
示例此处.
在 Rails 4 中,before_filter
的别名为 before_action
,skip_before_filter
的别名也为 skip_before_action
with Rails 4, before_filter
is aliased with before_action
, and skip_before_filter
is also aliased with skip_before_action
这篇关于before_filter 语法,当你想“除外"时控制器“abc"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!