问题
I have two models User and ActiveAdmin on which I want to apply my devise
integrations.
I have my custom_failure.rb
as follows
class CustomFailure < Devise::FailureApp
def redirect_url
login_path
end
# def redirect_url
# root_path
# end
def respond
if http_auth?
http_auth
else
redirect
end
end
end
Which seems to be working great.
Also, can define in my application controller
like :
def after_sign_in_path_for(resource)
# case resource
if resource.is_a?(Admin)
admin_dashboard_path
else
root_path
end
end
and
def after_sign_out_path_for(resource_or_scope)
login_path
end
But the issue is how to use this resource
in custom_failure.rb
so that I can redirect accordingly to login for user login
or for the admin login
?? Acc to current scenario it always redirects to the user login page ??
回答1:
Try putting custom_failure.rb
into you lib folder. Then make sure the file is loaded. Probably you would attempt to load all files in lib automatically.
Then Redirect to a specific page.
UPDATE:
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
来源:https://stackoverflow.com/questions/14829654/how-to-define-custom-failure-for-devise-in-case-of-two-different-models-user-and