命名空间控制器的过滤器

Filter for namespaced controllers

我在文件夹 /controllers/admin 中有一组控制器,它们看起来都像这样并且具有相同的 filter:

module Admin
  class UsersController < ApplicationController
    before_action :some_method

    #actions
  end
end

每个命名空间控制器如何从中央位置继承 before_action :some_method

您似乎需要在 Admin 模块命名空间中有一个单独的 Base 控制器:

class Admin::BaseController < ApplicationController
  before_action :some_method

  #actions
end

class Admin::UsersController < Admin::BaseController
  #some_method filter is invoked here
end

class Admin::PostsController < Admin::BaseController
  #some_method filter is invoke here
end