Rails:filter
来源:互联网 发布:南风知我意2txt书包网 编辑:程序博客网 时间:2024/05/16 10:39
filter
before_fil
before_fil
ter after_filter around_filter
设置filter的参数可以为一个方法symbol :method_a ,一个block 或者一个类, 该类的静态方法self.filter()会被调用 默认filter作用于当前类的所有action方法和子类的action方法, :only 和 :except用来在controller中包含或者排除action
before_filter 和after_filter默认是添加filter到filter chains最后, 如果要添加到最前使用prepend_before_filter() 和 prepend_after_filter()
before_filter 主要用来作验证 after_filter 主要用来控制内容(压缩,替换) around_filter 可以用来记录时间 设置参数必须为一个类, 该类有before(controller)和after(controller)两个方法 around_filter XXXFilter.new
around_filter的添加是嵌套的, around_filter A.new,B.new的结果如下 A.before B.before action..... B.after A.after 注意顺序和前面两个filter不一样
filter 在继承中的关系
子controller会执行所有父controller的filter,但是父不会执行子的filter
verification
设置filter的参数可以为一个方法symbol :method_a ,一个block 或者一个类, 该类的静态方法self.filter()会被调用 默认filter作用于当前类的所有action方法和子类的action方法, :only 和 :except用来在controller中包含或者排除action
before_filter 和after_filter默认是添加filter到filter chains最后, 如果要添加到最前使用prepend_before_filter() 和 prepend_after_filter()
before_filter 主要用来作验证 after_filter 主要用来控制内容(压缩,替换) around_filter 可以用来记录时间 设置参数必须为一个类, 该类有before(controller)和after(controller)两个方法 around_filter XXXFilter.new
around_filter的添加是嵌套的, around_filter A.new,B.new的结果如下 A.before B.before action..... B.after A.after 注意顺序和前面两个filter不一样
filter 在继承中的关系
子controller会执行所有父controller的filter,但是父不会执行子的filter
verification
verify指令可以看做一个专门抽出来的filter功能,当verify失败, 当前action就不会执行了 class BlogController < ApplicationController verify :only => :post_comment, :session => :user_id, :add_flash => { :note => "You must log in to comment"}, :redirect_to => :index #.... end 支持的参数如下启用条件 :only=>:name or [:name,...] :except=>name or [:name,...] 测试条件 :flash=>:key or [:key,...] flash中必须包含某些key :method=>:symbol or [:symbol,...] 请求必须是某些http 方法 :session=>:key or [:key,...] session中必须包含某些key 执行操作 :add_flash=>hash 把传入hash的值对写入flash中 :redirect_to=>params 跳转页面。
转自:http://blog.csdn.net/dazhi_100/article/details/13321929
阅读全文
0 0
- Rails:filter
- Rails:filter
- Rails:filter
- Rails:filter
- rails里的filter
- Rails源代码分析(7):ActionController::Filter(1)
- Rails源代码分析(8):ActionController::Filter(2)
- Rails源代码分析(9):ActionController::Filter(3)
- Rails
- Rails
- Rails
- rails
- Rails
- rails
- Rails
- Rails
- Rails
- Rails
- 大数据24小时:工业大数据产业应用联盟成立,微软投资5000万美元应对全球气候问题
- 简单进阶随手指移动的View
- 为什么要使用交叉编译
- 数据结果第八周项目4--稀疏矩阵的三元组表示的实现及应用
- postgreSQL 日期函数 Extract
- Rails:filter
- MYSQL浮点数float精度问题
- 使用Anaconda 查看 IPYNB文件,以及将文件复制在pycharm下
- 从零编程基础小白到专业数据分析师,你需要走多远
- 京东物流系统架构演进中的最佳实践
- 第五周 项目二 数据结构之自建算法库——链栈
- SDNUOJ 1213.金额的中文大写
- 全排列问题(c语言程序实现)
- php中的错误和异常处理