我有两种模式“用户”和“活动管理员”,我想在这两种模式上应用我的devise
集成。
我有我的custom_failure.rb
如下
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
这似乎效果很好。
另外,可以在我的中定义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
但问题是如何使用这个resource
in custom_failure.rb
这样我就可以相应地重定向到登录user login
或对于admin login
??根据当前场景,它总是重定向到用户登录页面?
尝试放置custom_failure.rb
进入你的 lib 文件夹。然后确保文件已加载。您可能会尝试自动加载 lib 中的所有文件。
Then 重定向到特定页面 https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-when-the-user-can-not-be-authenticated.
UPDATE:
你必须使用scope解决这个问题:-
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)