本文介绍了如何指定执行before_filters的顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

rails是否对使用以下两种用法之一执行过滤器之前的顺序做出任何保证:

Does rails make any guarantees about the order that before filters get executed with either of the following usages:

before_filter [:fn1, :fn2]

before_filter :fn1
before_filter :fn2

I' d感谢任何帮助。

I'd appreciate any help.

推荐答案

如果您引用,有一个子标题为过滤器链排序,下面是示例代码:

If you refer http://api.rubyonrails.org/v2.3.8/classes/ActionController/Filters/ClassMethods.html, there is a subheading called "Filter chain ordering", here is the example code from that:

class ShoppingController < ActionController::Base
    before_filter :verify_open_shop

class CheckoutController < ShoppingController
    prepend_before_filter :ensure_items_in_cart, :ensure_items_in_stock

根据解释:

因此您可以像这样明确地给出过滤器链的顺序。

So you can explicitly give the order of the filter chain like that.

这篇关于如何指定执行before_filters的顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 07:05