Devise redirect after login fail

  1. Create a custom_failure.rb in your lib directory, with:

     class CustomFailure < Devise::FailureApp
       def redirect_url
         your_path
       end
    
       def respond
         if http_auth?
           http_auth
         else
           redirect
         end
       end
     end
    
  2. In your Devise initializer, include:

       config.warden do |manager|
         manager.failure_app = CustomFailure
       end
    
  3. Make sure Rails is loading your lib files, in your application.rb :

     config.autoload_paths += %W(#{config.root}/lib)
    

Don’t forget to restart your server.

I don’t think there’s an easier way to do this.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)