2014-03-06 41 views
0

我試圖設置設計,使任何失敗的身份驗證重定向到註冊頁面,除了頁面中的標誌將重定向到自身。我有以下的自定義失敗等級:設計自定義redirect_url

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函數中檢測請求來自哪個頁面,以便我可以相應地重定向?

+1

'request.referer'應該給你從請求來自哪裏的URL。 'URI(request.referer).path',如果你只需要相關的url – usha

回答

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