Rails 4: before_filter vs. before_action

后端 未结 5 823
没有蜡笔的小新
没有蜡笔的小新 2020-11-27 09:39

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 b

5条回答
  •  独厮守ぢ
    2020-11-27 10:15

    To figure out what is the difference between before_action and before_filter, we should understand the difference between action and filter.

    An action is a method of a controller to which you can route to. For example, your user creation page might be routed to UsersController#new - new is the action in this route.

    Filters run in respect to controller actions - before, after or around them. These methods can halt the action processing by redirecting or set up common data to every action in the controller.

    Rails 4 –> _action

    Rails 3 –> _filter

提交回复
热议问题