2013-01-04 31 views
3

有設計問題。我有一個註冊的網址,其中包括令牌......是這樣的:本地主機:3000 /用戶/ sign_up/df293b00ae137b8b6436d45e622304aedc549072Rails/Devise:註冊失敗後,我如何重定向回來並顯示Flash消息?

當註冊失敗(密碼不匹配或某物)的應用重定向到本地主機:3000 /用戶,並顯示來自模型的正確的閃光消息。

但是我需要應用程序重新導向回到具有令牌的網址。所以我把redirect_to:放回到控制器中,讓我回來,但閃光消息不顯示。

如何讓頁面重定向回來(保留確切的url)並仍然顯示flash消息。

下面是從色器件控制器代碼:

def new 
    resource = build_resource({}) 
    respond_with resource 
    end 

    # POST /resource 
    def create 
    build_resource 

    if resource.save 
     if resource.active_for_authentication? 
     set_flash_message :notice, :signed_up if is_navigational_format? 
     sign_up(resource_name, resource) 
     respond_with resource, :location => after_sign_up_path_for(resource) 
     else 
     set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format? 
     expire_session_data_after_sign_in! 
     respond_with resource, :location => after_inactive_sign_up_path_for(resource) 
     end 
    else 
     clean_up_passwords resource 
     respond_with resource 
    end 
    end 

任何幫助將是巨大的!

+0

您是否嘗試過使用'flash.keep'前'redirect_to的:back'?這聽起來像Flash不是重定向的倖存者。 –

+0

是的,沒有骰子:(只是重定向回來沒有閃光信息 –

+0

重定向可能本身重定向了嗎?沿着[這個答案](http://stackoverflow.com/a/12880760/771564)。 –

回答

-1

你想要的是爲devise編寫一個自定義的FailureApp,它用於將用戶重定向到給定頁面,如果他不可驗證(驗證失敗)。

你可以看到是誰編寫和使用的色器件維基一個失敗的應用程序的更多信息:

https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-when-the-user-can-not-be-authenticated

+0

在這種情況下,我不認爲自定義的FailureApp有幫助。當*註冊*失敗時,OP不會嘗試保留原始URL,而不是當*登錄失敗時。 – denishaskin

相關問題