Rails 4:before_filter 与 before_action [英] Rails 4: before_filter vs. before_action

查看:32
本文介绍了Rails 4:before_filter 与 before_action的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Rails >4.0.0 中,生成器使用 before_action 而不是 before_filter 创建 CRUD 操作.它似乎在做同样的事情.那么这两者有什么区别呢?

In rails >4.0.0 generators creates CRUD operations with before_action not before_filter. It seems to do the same thing. So what's the difference between these two?

推荐答案

我们可以ActionController::Base中,before_action只是一个新语法 before_filter.

As we can see in ActionController::Base, before_action is just a new syntax for before_filter.

但是 before_filter 语法 Rails 5.0 中已弃用,将在 Rails 5.1

However the before_filter syntax is deprecated in Rails 5.0 and will be removed in Rails 5.1

这篇关于Rails 4:before_filter 与 before_action的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆