Last weekend had a small hackathon in our office and we build a simple group emailing service and in that project we need to make some overrides in devise and one of them was custom redirect in case login fails.
By default when the login fails it redirects to “users/sign_in”. Here is how you can over ride this.
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) |
4. Don’t forget to restart your server.
Thats a way to handle custom redirect after login fail in devise. Please feel free to embarrass me with your improvements in the comments.
The post Custom redirect after login fail in devise appeared first on Code Beer Startups.