How to make Devise redirect after confirmation

后端 未结 6 817
囚心锁ツ
囚心锁ツ 2020-12-02 13:07

How can I create an after-confirmation redirect in Devise?

Before I added the confirmation module the custom after_sign_up_path worked fine

6条回答
  •  孤街浪徒
    2020-12-02 13:43

    A less intrusive way of achieving this might be just overriding the after_confirmation_path_for method of Devise::ConfirmationsController.

    Create a new confirmations_controller.rb in app/controllers directory:

    class ConfirmationsController < Devise::ConfirmationsController
    
      private
    
      def after_confirmation_path_for(resource_name, resource)
        your_new_after_confirmation_path
      end
    
    end
    

    In config/routes.rb, add this line so that Devise will use your custom ConfirmationsController. This assumes Devise operates on users table (you may edit to match yours).

    devise_for :users, controllers: { confirmations: 'confirmations' }
    

    Restart the web server, and you should have it.

提交回复
热议问题