2011-12-01 37 views

回答

8

你將不得不創建一個從設計的FailureApp繼承這裏看到一個自定義FailureApp:https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-when-the-user-can-not-be-authenticated

+1

這種方法(對於一個至少在這個環節)的問題是它推動你上申請,如果你不把你的密碼正確的註冊(例如)... –

+0

這是最好的練習答案,不要導致實現自己的'before_filter'解決方案! – equivalent8

45

我有地方,我需要重定向到註冊,如果用戶沒有登錄類似的問題。 我通過向application_controller.rb添加方法並將其用作其他控制器中的before過濾器來修復它。

請記住,這是一個臨時解決方案,因爲它跳過了一堆設計的抽象。

 

before_filter :auth_user 

    def auth_user 
    redirect_to new_user_registration_url unless user_signed_in? 
    end 
 
+0

謝謝!這工作! :D – Sheharyar

+0

很高興能幫到你= = – Baconator507

+2

這應該是被接受的答案。 –