cannot create two CustomFailure redirect behaviors for devise, one for user another for admin_user

StackOverflow https://stackoverflow.com/questions/9317991

سؤال

I am using active_admin in my rails app. Previously, I used to render a custom page on devise login failed. The problem now is that the same custom page gets rendered if active_admin login fails too.

I am stuck with this problem and too far along my development to give up active_admin. Please help.

My CustomFailure definition is here :

class CustomFailure < Devise::FailureApp
  def redirect_url 
    signin_path
  end

  def respond
    if http_auth? 
      http_auth
    else
      redirect
    end
  end
end

Could someone tell me how to modify the code to have redirect paths for user signin failed and admin_user signin failed. My admin user signin path is : admin_user_session_path

هل كانت مفيدة؟

المحلول

You have to use scope to solve this :-

class CustomFailure < Devise::FailureApp 
  def redirect_url 
    if warden_options[:scope] == :user 
      signin_path 
    else 
      new_admin_user_session_path 
    end 
  end 
  def respond 
    if http_auth? 
      http_auth 
    else 
      redirect 
    end 
  end 
end 

hope this helps :)

نصائح أخرى

application_controller.rb

...
def after_sign_in_path_for(resource_or_scope)
  if admin_user
   redirect_to whatever_path
  else
   root_path
  end
end
...

I may not know the correct call for the admin user but this should work.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top