Where to put a before_filter shared between multiple controllers

后端 未结 4 748
旧巷少年郎
旧巷少年郎 2021-01-02 01:55

I have multiple controllers that all use an identical before_filter. In the interests of keeping things dry, where should this method live so that all the controllers can us

4条回答
  •  佛祖请我去吃肉
    2021-01-02 02:56

    Something like this can be done.

    Class CommonController < ApplicationController
      # before_filter goes here
    end
    
    Class MyController < CommonController
    end
    
    class MyOtherController < CommonController
    end
    

提交回复
热议问题