Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何让活动管理员在登录后与权威人士一起工作_Ruby On Rails_Ruby_Ruby On Rails 4_Activeadmin_Pundit - Fatal编程技术网

Ruby on rails 如何让活动管理员在登录后与权威人士一起工作

Ruby on rails 如何让活动管理员在登录后与权威人士一起工作,ruby-on-rails,ruby,ruby-on-rails-4,activeadmin,pundit,Ruby On Rails,Ruby,Ruby On Rails 4,Activeadmin,Pundit,我已将配置权威添加到我的应用程序中 config.authorization_adapter = ActiveAdmin::PunditAdapter 当我使用admin@example.com我收到了这个错误 Pundit::NotDefinedError in Admin::Dashboard#index unable to find policy AdminUserPolicy Extracted source (around line #2): insert_tag active_

我已将配置权威添加到我的应用程序中

config.authorization_adapter = ActiveAdmin::PunditAdapter
当我使用admin@example.com我收到了这个错误

Pundit::NotDefinedError in Admin::Dashboard#index
unable to find policy AdminUserPolicy

Extracted source (around line #2):

insert_tag active_admin_application.view_factory["page"]
所以我在我的policies/active_admin文件夹中创建了这些文件

adminuser_policy.rb

module ActiveAdmin
class AdminUserPolicy < ApplicationPolicy
class Scope < Struct.new(:user, :scope)
  def resolve
    scope
  end
end
def home?
true
end

def index?
true 
end
def show?
true 
end
def new?
true
end

def create?
 true
end

def update?
true 
end

  def destroy?
    true 
 end
end
module ActiveAdmin
class PagePolicy < ApplicationPolicy
  class Scope < Struct.new(:user, :scope)
  def resolve
    scope
  end
 end
   def index?
      true
   end

   def show?
     true
   end
  end
end
模块ActiveAdmin
类AdminUserPolicy<应用程序策略
类范围
结束

page_policy.rb

module ActiveAdmin
class AdminUserPolicy < ApplicationPolicy
class Scope < Struct.new(:user, :scope)
  def resolve
    scope
  end
end
def home?
true
end

def index?
true 
end
def show?
true 
end
def new?
true
end

def create?
 true
end

def update?
true 
end

  def destroy?
    true 
 end
end
module ActiveAdmin
class PagePolicy < ApplicationPolicy
  class Scope < Struct.new(:user, :scope)
  def resolve
    scope
  end
 end
   def index?
      true
   end

   def show?
     true
   end
  end
end
模块ActiveAdmin
类PagePolicy<应用程序策略
类范围
我错过了什么?谢谢你的帮助

我找到了答案

将这两行添加到活动管理初始值设定项文件后

config.authorization_adapter = ActiveAdmin::PunditAdapter 

#this line sets the default policy to application_policy.rb
config.pundit_default_policy = "ApplicationPolicy"
我必须将此添加到app/admin/dashboard.rb下的dashboard.rb

def index
  authorize :dashboards, :index?
end
然后,我在策略文件夹中创建了一个名为dashboard_policy.rb的文件,并添加了以下代码

class DashboardPolicy < ApplicationPolicy
   def dashboard?
   true
  end
  def index?
   true
  end
 end
class仪表板策略

这就成功了

是的,你上面粘贴的代码完全被破坏了。具体来说,请提供app/admin/dashboard.rb文件的完整内容。