Rails 4: before_filter vs. before_action

后端 未结 5 822
没有蜡笔的小新
没有蜡笔的小新 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:02

    It is just syntax difference, in rails app there is CRUD, and seven actions basically by name index, new, create, show, update, edit, destroy.

    Rails 4 make it developer friendly to change syntax before filter to before action.

    before_action call method before the actions which we declare, like

    before_action :set_event, only: [:show, :update, :destroy, :edit]
    

    set_event is a method which will call always before show, update, edit and destroy.

提交回复
热议问题