Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise redirect after login fail

All the questions I've found are related for a successful login with the helper after_sign_in_path_for(resource)

I have a login form in the index of the site, and when the login fails it redirects to "users/sign_in"

But how can I redirect to my "site#index" when the login fails?

like image 443
Juanjo Avatar asked Apr 29 '11 13:04

Juanjo


1 Answers

  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 you Devise initializer, include:

      config.warden do |manager|     manager.failure_app = CustomFailure   end 
  3. Make sure Rails is loadin 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. Good luck.

like image 74
Marco Antonio Avatar answered Sep 27 '22 17:09

Marco Antonio