指定要从before_filter中排除哪些控制器 [英] Specify which controllers to exclude from before_filter

查看:186
本文介绍了指定要从before_filter中排除哪些控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用devise进行身份验证,并在我的应用程序控制器中有一些before_filters。问题我看到的是,当我尝试注销before_filter拦截,并让我在我在before_filter中设置的视图。有没有办法指定哪些控制器应该从应用程序控制器或其他文件中排除?

解决方案

您可以符合条件的过滤器:仅

  before_filter:filter_name,:except => [:action1,action2] 

或者如果过滤器(如我现在看到的那样)情况)在 ApplicationController 中定义,您希望在子类控制器中绕过它,您可以使用 skip_before_filter 子类控制器中的资格相同:

  skip_before_filter:filter_name,:except => [:action1,:action2] 


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?

解决方案

You can qualify a filter with :only or :except.

before_filter :filter_name, :except => [:action1, :action2]

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 a skip_before_filter with the same qualifications in the subclass controller:

skip_before_filter :filter_name, :except => [:action1, :action2]

这篇关于指定要从before_filter中排除哪些控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆