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