我正在尝试设置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
函数中检测请求来自哪个页面,以便我可以相应地重定向?
答案 0 :(得分:1)
尝试:
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