ruby-on-rails - 安装 pundit 后尝试创建用户时出错
问题描述
在我的项目中安装 pundit 后,每当我尝试创建新用户时,都会出现以下错误。即使我安装了它并包含了 gem 并运行了 bundle install,它似乎也找不到 pundit。
app_1 | ActionController::RoutingError (uninitialized constant ApplicationController::Pundit):
app_1 |
app_1 | app/controllers/application_controller.rb:3:in `<class:ApplicationController>'
app_1 | app/controllers/application_controller.rb:1:in `<top (required)>'
app_1 | app/controllers/v1/users_controller.rb:1:in `<top (required)>'
我的 ApplicationController.rb
class ApplicationController < ActionController::API
before_action :authenticate_user!
include Pundit
after_action :verify_authorized, except: :index, unless: :skip_pundit?
after_action :verify_policy_scoped, only: :index, unless: :skip_pundit?
private
def skip_pundit?
devise_controller? || params[:controller] =~ /(^(rails_)?admin)|(^pages$)/
end
end
解决方案
推荐阅读
- variables - 我如何在容器中调用 _email ?在 Flutter Android 应用程序中
- flutter - 陷入了许多问题
- mysql - 如何根据分区在mysql中执行排名
- python - Python - 如何在 HTML 中查找所有具有模式的子字符串?
- vtk - 将 VtkVolume 保存为 stl 文件(3d 数据)?
- javascript - 从 React 类导出函数
- javascript - 如何将本地 javascript 添加到 vue 组件?
- c# - BackgroundWorker 在方法正在执行时显示进度
- java - 无法使用 ProjectExecutionServices 创建 TaskExecuter 类型的服务
- python - 将 xmltodict 模块导入 Visual Studio 代码