过滤命名空间控制器

时间:2015-11-06 19:32:33

标签: ruby-on-rails ruby-on-rails-4 ruby-on-rails-4.2 actionpack

我在/ controllers / admin文件夹中有一组控制器,它们看起来都像这样filter

module Admin
  class UsersController < ApplicationController
    before_action :some_method

    #actions
  end
end

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

1 个答案:

答案 0 :(得分:1)

管理模块命名空间中似乎需要一个单独的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