指定要从 before_filter 中排除的控制器
我正在使用 devise 进行身份验证,并在我的应用程序控制器中有一些 before_filters 。我看到的问题是,当我尝试注销时,before_filter 会拦截该内容并使我保持在我在 before_filter 中设置的视图上。有什么方法可以让我指定哪些控制器应该从应用程序控制器或其他文件中排除?
I'm using devise for authentication and have some before_filters in my application controller. Issue I'm seeing is that when I try to logout the before_filter intercepts that and keeps me on the view that's I've setup in the before_filter. Is there any way for me to specify which controllers should be excluded from the application controller or some other file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在您想要跳过继承控制器中指定的 before 过滤器的控制器中,您可以告诉 Rails 跳过该过滤器
In the controller where you want to skip a before filter specified in an inherited controller, you can tell rails to skip the filter
您可以使用
:only
或: except
限定过滤器。或者,如果过滤器(正如我现在看到的情况就是您的情况)是在
ApplicationController
中定义的,并且您想在子类控制器中绕过它,则可以使用skip_before_filter
在子类控制器中具有相同的资格:You can qualify a filter with
:only
or:except
.Or if the filter (as I now see is the case in your situation) is defined in
ApplicationController
and you want to bypass it in a subclass controller, you can use askip_before_filter
with the same qualifications in the subclass controller:在 config/application.rb 中
引用者:
如何跳过 before_filter对于 Devise 的 SessionsController?
In config/application.rb
Referenced by:
How to skip a before_filter for Devise's SessionsController?
上面的答案都很好,除了:
<代码>
弃用警告:skip_before_filter 已弃用,并将在 Rails 5.1 中删除。请改用skip_before_action。
因此,请使用
before_action
和skip_before_action
而不是*-filter
。Answers above are good except:
DEPRECATION WARNING: skip_before_filter is deprecated and will be removed in Rails 5.1. Use skip_before_action instead.
So please use
before_action
andskip_before_action
instead of*-filter
.