[英]Devise custom redirect_url
我正在尝试将Devise设置为使任何失败的身份验证都重定向到注册页面,但登录页面除外,它将重定向到其自身。 我有以下自定义失败类:
class CustomFailure < Devise::FailureApp
def redirect_url
new_user_registration_path
end
def respond
if http_auth?
http_auth
else
redirect
end
end
end
麻烦的是,即使是登录失败的帖子也会重定向到注册。 如何在redirect_url
函数中检测请求来自哪个页面,以便可以相应地重定向?
尝试:
redirect_path = "whareveeeeeeer.com"
redirect_to redirect_path
我在我的DELETE方法中使用它:
# DELETE /resource/sign_out
def destroy
redirect_path = after_sign_out_path_for(resource_name)
signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
set_flash_message :notice, :signed_out if signed_out && is_flashing_format?
yield resource if block_given?
# We actually need to hardcode this as Rails default responder doesn't
# support returning empty response on GET request
respond_to do |format|
format.all { head :no_content }
format.any(*navigational_formats) { redirect_to redirect_path }
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.