gpt4 book ai didi

ruby-on-rails - Rails_admin 和专家:未定义方法 `policy' #
转载 作者:行者123 更新时间:2023-12-04 22:28:56 27 4
gpt4 key购买 nike

enter image description here
我在 rails 5 上,我正在尝试使用专家为我的 rails_admin 面板实现授权。所以我在我的应用程序 Controller 中包含了 Pundit 并安装了 the rails_admin_pundit gem正如你在我的 Gemfile 的这个片段中看到的:

gem 'devise'
gem 'devise-i18n'
gem 'rails_admin', '~> 1.0'
gem 'rails_admin-i18n'
gem 'rails_admin_tag_list', github: 'kryzhovnik/rails_admin_tag_list'
gem 'pundit'
gem "rails_admin_pundit", :github => "sudosu/rails_admin_pundit"

申请政策:
class ApplicationPolicy
attr_reader :current_user, :record

def initialize(current_user, record)
@user = current_user
@record = record
end

def index?
false
end

def show?
scope.where(:id => record.id).exists?
end

def create?
false
end

def new?
create?
end

def update?
false
end

def edit?
update?
end

def destroy?
false
end

def rails_admin?(action)
case action
when :dashboard
@user.admin?
when :index
@user.admin?
when :show
@user.admin?
when :new
@user.admin?
when :edit
@user.admin?
when :destroy
@user.admin?
when :export
@user.admin?
when :history
@user.admin?
when :show_in_app
@user.admin?
else
raise ::Pundit::NotDefinedError, "unable to find policy #{action} for #{record}."
end
end

end

以及我的 rails_admin 初始值设定项的片段:
RailsAdmin.config do |config|
config.authorize_with :pundit
config.current_user_method(&:current_user)
...
end

所以现在当我加载管理仪表板(网址:“/admin”)时,我收到此错误:

undefined method `policy' for #RailsAdmin::MainController:0x0055914e2523a0>



我遵循了所有说明,但我仍然看不到缺少什么。任何答案/建议将不胜感激。

最佳答案

这也困扰着我。最终找到:https://travis-ci.org/sferik/rails_admin/jobs/152180750

rails_admin 现在默认为 ::ActionController::Base
要修复,请将以下内容放入 rails_admin.rb:
config.parent_controller = '::ApplicationController'

关于ruby-on-rails - Rails_admin 和专家:未定义方法 `policy' #<RailsAdmin::MainController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40377340/

27 4 0

Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com