首页 > 解决方案 > 安装 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

标签: ruby-on-railsrubypundit

解决方案


推荐阅读