簡體   English   中英

Rails Pundit ActiveAdmin:頁面未正確重定向

[英]Rails Pundit ActiveAdmin: page isn’t redirecting properly

我安裝了 Activeadmin 和 Pundit gems。

在 application_controller.rb 中添加了“include Pundit”。

定義的 package_policy.rb

class PackagePolicy < ApplicationPolicy
  def update?
    user.admin?
  end
end

application_policy.rb:

class ApplicationPolicy
  attr_reader :user, :record

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

  def index?
    false
  end

  def show?
    false
  end

  def create?
    false
  end

  def new?
    create?
  end

  def update?
    false
  end

  def edit?
    update?
  end

  def destroy?
    false
  end

  def scope
    Pundit.policy_scope!(user, record.class)
  end

  class Scope
    attr_reader :user, :scope

    def initialize(user, scope)
      @user = user
      @scope = scope
    end

    def resolve
      scope
    end
  end
end

而且比我得到的

page isn’t redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete

在我的瀏覽器中。 也許,它是無限循環或類似的東西。

我對 package_policy.rb 進行了一些不同的配置,但在添加了 application_policy.rb 之后 - 結果在嘗試登錄到 Activeadmin 面板后瀏覽器中總是出錯。

我允許我的 ApplicationPolicy 中所有方法的所有操作。

在我為我的資源創建具有所需權限的新策略之后。

在應用策略中:

...
  def index?
    true
  end

  def show?
    true
  end

  def create?
    true
  end

  def new?
    create?
  end

  def update?
    true
  end

  def edit?
    update?
  end

  def destroy?
    true
  end
...

在任何其他政策中,例如:

...
  def index?
    user.admin?
  end

  def show?
    user.admin?
  end

  def create?
    user.admin?
  end

  def new?
    create?
  end

  def update?
    user.admin?
  end

  def edit?
    update?
  end

  def destroy?
    user.admin?
  end
...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM