我在/ controllers / admin文件夹中有一组控制器,它们看起来都像这样filter
:
module Admin
class UsersController < ApplicationController
before_action :some_method
#actions
end
end
每个命名空间控制器如何从中心位置继承before_action :some_method
?
答案 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