`
jbf034
  • 浏览: 152308 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Filter chain skipping --- 跳过过滤器链

阅读更多
Filter chain skipping --- 跳过过滤器链

有时候在一个超类内指定对大多数子类,而不是全部子类有效的过滤器链会带来工作上的方便。

class ApplicationController < ActionController::Base

before_filter :authenticate

end




class WeblogController < ApplicationController

# 会执行:authenticate 过滤器

end




class SignupController < ApplicationController

# 将不会执行:authenticate 过滤器

skip_before_filter :authenticate

end




F、Filter conditions --- 过滤器条件

过滤器可以被限制为只对指定动作有效。这可通过列出被排除的动作,或列出要包含的动作给过滤器来做到。有效的条件是nly 或 :except ,两者都接受任意数量的方法引用。例如:

class Journal < ActionController::Base

# only require authentication if the current action is edit or delete

before_filter :authorize,nly => [ :edit, :delete ]




private

def authorize

# redirect to login unless authenticated

end

end

当给内联方法(proc)过滤器设置条件时,条件必须首先出现,并放置在圆括号内。

class UserPreferences < ActionController::Base

before_filter(:except => :new) { # some proc ... }

# ...

end




1、after_filter(*filters, &block) 或 append_after_filter(*filters, &block) 被传递的filters将被附加给过滤器数组,过滤器在这个控制器的动作完成后执行。




2、before_filter(*filters, &block) 或 append_before_filter(*filters, &block) 被传递的filters将被附加给过滤器数组,过滤器在这个控制器的动作完成之前执行。




3、around_filter(*filters) 或 append_around_filter(*filters) The passed filters will have their before method appended to the array of filters that’s run both before actions on this controller are performed and have their after method prepended to the after actions. 此filter对象必须对before和after两者作出响应。所以,如果你使用了append_around_filter A.new, B.new, 则调用堆栈看起来似这样:

B#before

A#before

A#after

B#after




4、prepend_after_filter(*filters, &block) 被传递的filters将被添加到过滤器链的头部。




5、prepend_around_filter(*filters) The passed filters will have their before method prepended to the array of filters that’s run both before actions on this controller are performed and have their after method appended to the after actions. The filter objects must all respond to both before and after. So if you do prepend_around_filter A.new, B.new, the callstack will look like:

A#before

B#before

B#after

A#after




6、prepend_before_filter(*filters, &block)




7、skip_after_filter(*filters) 从after过滤链中移除指定的过滤器。注意这只是跳过方法引用过滤器的工作,不是指proc。这对管理在继承体系内摘出一个需要不同体系的子类很有用。

你也可以通过使用nly 和 :except 来控制跳过过滤器的动作。




8、skip_before_filter(*filters) 从before 过滤链中移除指定的过滤器。注意这只是跳过方法引用过滤器的工作,不是指proc。这对管理在继承体系内摘出一个需要不同体系的子类很有用。

你也可以通过使用nly 和 :except 来控制跳过过滤器的动作。
分享到:
评论
2 楼 mysky1984 2008-10-31  
:cry::arrow::idea:
1 楼 shaka 2008-08-28  
受用,考虑过这个问题没有?

如何给过滤器传参数,或者在子类过滤器中调父类的方法,然后传个参数过去,并在子类中取的方法的返回值?

相关推荐

    Skipping-Stones-Simulation-GUI:这是基于关联的实际物理模型的带有GUI的跳石现象的模拟

    跳过石头模拟GUI 这是基于关联的实际物理模型的跳石现象的模拟。 GUI允许您更改宝石的不同参数,包括:初始位置,初始速度,初始角度,宝石质量。 有关该项目的视频模拟,请访问: : 要运行GUI,只需运行hello.m...

    Skipping stone

    "Skipping stone"是一款专为多引力辅助轨迹设计的软件,其核心功能是利用多引力助推技术来优化航天器的轨道路径。多引力辅助(MGA,Multiple Gravity Assist)是一种复杂而高效的航天轨迹规划方法,它允许航天器利用...

    脉冲序列调制脉冲跳周期调制Buck变换器研究-脉冲序列调制_脉冲跳周期调制Buck变换器研究.rar

    脉冲序列调制脉冲跳周期调制Buck变换器研究-脉冲序列调制_脉冲跳周期调制Buck变换器研究.rar 脉冲序列调制-脉冲跳周期调制Buck变换器研究 摘要:脉冲序列调制(Pulse Train Modulation,简称PTM)采用高、低能量...

    maven 过滤文件夹打包

    "maven 过滤文件夹打包"这个主题涉及到的是如何利用Maven的资源过滤功能来实现针对不同运行环境的配置文件打包。下面将详细解释这一过程。 在开发环境中,我们通常会有多种配置文件,比如`application-dev....

    谷歌浏览器linux版google-chrome-stable_current_amd64.deb

    这是一个可以傻瓜式一键安装在debian,ubuntu,deepin等linux系统的谷歌浏览器deb格式安装包

    BIG文件编辑器

    BIG文件编辑器 FinalBIG Version 0.4 Beta released March 20th, 2006. Copyright by Matthias Wagner 2006 C&C Generals is a trademark or registered trademark of Electronic Arts in the USA and/or other ...

    在链接中禁用“跳墨”。「Disables 'ink skipping' in links.」-crx插件

    禁用文字修饰跳过墨迹 恢复以前的Chrome版本63或更早版本的下划线行为。 Chrome 64默认实现墨水跳过! *新增*:“作为一项法律解决方案,Google删除了其流行的“查看图像”功能。该功能以前允许用户下载和保存照片,...

    kernel-devel.zip,kernel-devel-3.10.0-1127.18.2.el7.x86_64.rpm

    离线环境下,在centos7.6系统上安装kernel-devel-3.10.0-1127.18.2.el7.x86_64.rpm版本,其中kernel-devel-3.10.0-1127.18.2.el7.x86_64.rpm在kernel-devel压缩文件里面,依赖包完整,解压后直接./install.sh即可 ,...

    jquery ajax表单提交

    log('ajaxSubmit: skipping submit process - no element selected'); return this; } var method, action, url, $form = this; if (typeof options == 'function') { options = { success: options }; } ...

    GBK文件夹转化UTF-8 支持文件名

    .filter(path -&gt; !path.toFile().isDirectory()) .forEach(path -&gt; convertFile(path, targetDir)); } catch (IOException e) { e.printStackTrace(); } } private static void convertFile(Path sourcePath...

    wix310.exe & innosetup-5.6.1

    [INFO] Skipping 'EXE 安装程序' because of configuration error '找不到 InnoSetup 编译器 (iscc.exe)。' Advice to fix: 从 http://www.jrsoftware.org 下载 InnoSetup 5 或更高版本, 然后将其添加到 PATH。 ...

    linux compat-libstdc++-33-3.2.3-72.eI7.x86_64.rpm

    linux compat-libstdc++-33-3.2.3-72.eI7.x86_64.rpm.

    kernel-3.10.0-957.27.2.el7.x86_64.rpm

    kernel-3.10.0-957.27.2.el7.x86_64.rpm

    二年级下英语教学设计-Module5Unit1 Lingling is skipping .外研社(一起).doc

    此单元的教学目标旨在让学生掌握使用动词-ing形式描述正在进行的动作,例如:"Lingling is skipping." 和 "Daming and Sam are playing hide-and-seek." 这样的现在进行时态的句子结构。教学内容还包括其他类似句型...

    cyrus-sasl-2.1.26-23.el7.x86_64.rpm

    离线安装包,亲测可用

    erlang-xmerl-22.2.4-1.el7.x86_64.rpm

    erlang-xmerl-22.2.4-1.el7.x86_64.rpm 免费下载0积分镜像下载。rabbitMQ安装需要依赖此环境。Erlang 是一种多用途编程语言,主要用于开发并发和分布式系统。它最初是一种专有的编程语言,Ericsson 使用它来开发电话和...

    PyPI 官网下载 | gordian-1.1.3.tar.gz

    《PyPI官网下载 | gordian-1.1.3.tar.gz——深入了解Python库的发布与使用》 在Python的世界里,PyPI(Python Package Index)是最重要的资源库,它为全球的开发者提供了一个集中地来发布、分享和发现Python软件包...

    PAM2308 Dual High-Efficiency PWM Step-Down DC-DC Coverter

    为了确保便携式设备能够拥有更长的电池寿命,PAM2308提供了节能的脉冲跳过调制(Pulse-Skipping Modulation, PSM)模式来降低轻负载下的静态电流。 #### 二、主要特性 - **高效率**:最高可达96%的转换效率。 - **低...

    Disables 'ink skipping' in links.-crx插件

    禁用文本装饰跳过墨水 恢复以前的Chrome版本63或更早版本的下划线行为。 Chrome 64默认实现墨水跳过! *新增*:“作为一项法律解决方案,Google删除了其流行的“查看图像”功能。该功能以前允许用户下载和保存照片,...

Global site tag (gtag.js) - Google Analytics