簡體   English   中英

使用cancancan時確認Devise用戶時出錯

[英]Error when confirming Devise user while using cancancan

按照為用戶注冊發送的 email 中的確認鏈接給出此錯誤:

uninitialized constant Confirmation 
NameError in Devise::ConfirmationsController#show 

但是,如果我通過刪除ApplicationController中的load_and_authorize_resource來關閉Cancancan ,則不會發生錯誤,並且用戶可以成功點擊確認鏈接。

我已經嘗試在覆蓋的 Devise controller 中添加skip_load_and_authorize_resource用於確認Users::ConfirmationsController < Devise::ConfirmationsController

在此處輸入圖像描述

根據您的解釋,可能性是:

  1. The reason of uninitialized constant Confirmation might be that it is trying to find out the model associated with this controller using the controller name and the result it gets is Confirmation but there is no model with that name.
  2. 在覆蓋的 controller 本身中有show操作之前, skip_load_and_authorize_resource可能無法工作(在子 class 上添加之前的操作不應該在父 ZA2F2ED4F8EBC2CBB4C21A29DC40AB61 上工作)

我不確定這是否可行,但您可以嘗試這樣的事情並在您的ApplicationController中查看:

load_and_authorize_resource unless: :devise_controller?

所以這將跳過所有before_action控制器的 before_action。

load_and_authorize_resource 不應該在 ApplicationController 中使用,因為它與 devise 和沒有同名模型的控制器不兼容。 而是根據需要在每個 controller 中設置 load_and_authorize_resource。

暫無
暫無

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

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