ruby-on-railsdevisecancancandevise-confirmable

Error when confirming Devise user while using cancancan


Following the confirm link in the email that gets sent for a user signup gives this error:

uninitialized constant Confirmation 
NameError in Devise::ConfirmationsController#show 

But if I turn off Cancancan by removing load_and_authorize_resource in the ApplicationController, the error doesn't happen and the user can successfully follow the confirm link.

I've tried adding skip_load_and_authorize_resource in an overrided Devise controller for the Confirmations-- Users::ConfirmationsController < Devise::ConfirmationsController.

enter image description here


Solution

  • The possibilities according to your explanation are:

    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. The skip_load_and_authorize_resource might not work until you have the show action in your overrided controller itself (adding a before action on child class should not work on parent class I think)

    I am not sure if this will work or not but you can try something like this and see in your ApplicationController:

    load_and_authorize_resource unless: :devise_controller?
    

    So this will skip that before_action for all devise controllers.