2013-01-15 83 views
2

我跟着這個問題Devise redirect after login fail它工作的很好,但我得到一個Flash通知告訴我,我需要登錄才能繼續,並且我需要的消息是密碼或電子郵件無效。所以我說在CustomFailure這樣閃光的通知:設計登錄失敗消息

class CustomFailure < Devise::FailureApp 
    def redirect_url 
    root_path 
    end 

    def respond 
    if http_auth? 
     http_auth 
    else 
     flash[:error] = I18n.t(:invalid, :scope => [ :devise, :failure ]) 
     redirect 
    end 
    end 
end 

,現在它的顯示我兩個消息,無效的密碼和未,我怎麼能消除未經驗證的消息?

回答

1

設計未設置flash[:error],但flash[:alert]當登錄失敗時,嘗試在您的應用程序中設置此項。

你也可以只覆蓋方法Devise::FailureApp#i18n_message並使其返回您所選擇的消息:

class CustomFailure < Devise::FailureApp 
    def redirect_url 
    root_path 
    end 

    def i18n_message 
    "Hello World" # you might go for something more elaborate here 
    end 
end 
+0

非常感謝您的回答。這對我不起作用,因爲我只想在登錄失敗時顯示消息「無效的密碼或電子郵件」,並且當用戶嘗試進入無法訪問的頁面(如果他未通過身份驗證時),我會想要顯示未經認證的消息。如果我覆蓋該方法並將「未認證」更改爲「無效」,則會始終顯示消息「無效的電子郵件或密碼」 – dcarey