Devise Custom Redirect for Failed Login

If you're failed to login , Devise gem will redirect you to /users/sign_in (back to login page) by default. But there's a high probability you need to adjust it. How to do that ?

Create a custom_redirection.rb file under lib folder, and fill that file with this :

class CustomRedirection < Devise::FailureApp
   def redirect_url
     #Your custom redirect path goes here, do whatever you need here
   end
   def respond
     if http_auth?
       http_auth
     else
       redirect
     end
   end
 end
And then, add the following codes to your devise.rb , originally some of them were commented out. Just enable and custom it like this one
 config.warden do |manager|
  #   manager.intercept_401 = false
  #   manager.default_strategies(:scope => :user).unshift :some_external_strategy
    manager.failure_app = CustomRedirection
  end
At last , make sure you have this line : config.autoload_paths = %W(#{config.root}/lib) on your application.rb, restart your web server and try to make a failed login.