haseeb haseeb - 7 months ago 5
Ruby Question

Redirect after only signup and login failure in devise rails

My login and signup forms are on home/index.html.erb. I want that when any of them fail error should show on index.html.erb . Now it redirect to devise views.
How can I do that?

Note : I want this only for signup and login. Password Forgot scenario will remain

devise
default

Answer

you can do like this:

create class on lib folder and overwrite devise failure

class CustomFailure < Devise::FailureApp
  def redirect_url
     #your path
  end

  def respond
    if http_auth?
     http_auth
   else
     redirect
   end
 end

end

And put this config/initializers/devise.rb

  config.warden do |manager|
    manager.failure_app = CustomFailure
  end

One more thing you have to auto load lib file like:

config.autoload_paths << Rails.root.join('lib')

put this line at config/application.rb

I hope that will work

EDITED

 def redirect_url

    if request.referrer.include? new_user_session_path.split("/").last
       #your path
    else
       new_user_session_path
    end
 end
Comments