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

cassiuschen · 2014年01月15日 · 最后由 cassiuschen 回复于 2014年01月17日 · 6202 次阅读

我看很多人的 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.

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

需要 登录 后方可回复, 如果你还没有账号请 注册新账号