Back to Devise Wiki

How To: Redirect To A Specific Page When The User Email Is Not Confirmed?

How-To:-Redirect-to-a-specific-page-when-the-user-email-is-not-confirmed?.md

latest1.1 KB
Original Source

If a user is not confirmable you can redirect to a specific page.

This example shows how to redirect to unconfirmed email information page when unconfirmed user want's to login.

<pre><code># written on lib/devise/custom_failure_app.rb class CustomFailureApp < Devise::FailureApp def redirect_url if warden_message == :unconfirmed return email_confirm_path(email: params[:user][:email]) end super end # You need to override respond def respond if warden_message == :unconfirmed Rails.logger.debug "redirect" return redirect end super end end </code></pre>

And add the following in config/initializers/devise.rb:

<pre><code> config.warden do |manager| manager.failure_app = CustomFailureApp end </code></pre>

If you're getting an uninitialized constant CustomFailureApp error, and you've put the CustomFailureApp class under your /lib directory, make sure to autoload your lib files in your application.rb file, like below

<pre><code> config.autoload_paths << Rails.root.join('lib').join('devise') </code></pre>