新手问题 Rails4.0 之后改 before_filter 后有什么变化么?

cassiuschen · January 15, 2014 · Last by cassiuschen replied at January 17, 2014 · 6202 hits

我看很多人的 Rails 4.0+ 项目都还在用 before_filter 啊……没有传说中把 filter 改成 action…… 没搞懂这其中什么区别…………

以及现在 4.1.0b1 写before_filter RubyCAS::GatewayFilter, :only => :explore的话 rails 会抛出 undefined method 'before' for RubyCAS::Filter:Class不知什么情况…………求指导……

before_filter 已经不推荐使用了,推荐使用 before_action https://github.com/rails/rails/commit/9d62e04838f01f5589fa50b0baa480d60c815e2c

#1 楼 @jianpanxiu 只是改名而已,行为和之前是一样的。

#1 楼 @jianpanxiu

Rename all action callbacks from *_filter to *_action to avoid the misconception that these callbacks are only suited for transforming or halting the response.

原来是为了更准确地描述使用场景,减少歧义。

You need to Sign in before reply, if you don't have an account, please Sign up first.