註冊後,需要確認,我的應用程序重定向到已驗證頁面,以便驗證失敗,並且設計重定向到登錄路徑。當設計重定向到登錄路徑時如何flash.keep
由於第二次重定向,註冊後我的Flash信息丟失。
在重定向到登錄路徑,application_controller.rb或助手之前,是否有某處可以添加flash.keep
?如果還有其他選擇,我不希望爲此重寫一個設計控制器。
註冊後,需要確認,我的應用程序重定向到已驗證頁面,以便驗證失敗,並且設計重定向到登錄路徑。當設計重定向到登錄路徑時如何flash.keep
由於第二次重定向,註冊後我的Flash信息丟失。
在重定向到登錄路徑,application_controller.rb或助手之前,是否有某處可以添加flash.keep
?如果還有其他選擇,我不希望爲此重寫一個設計控制器。
註冊後,我存儲在會話中的提示信息重定向到登錄路徑踢之前(因爲用戶是未經證實它的「after_ 不活躍 _sign_up_path_for( )「)
設計註冊記憶控制器:
class RegistrationsController < Devise::RegistrationsController
protected
def after_inactive_sign_up_path_for(resource)
# store message to be displayed after redirection to login screen
session[:registration_flash] = flash[:notice] if flash[:notice]
super
end
end
然後我顯示此消息,如果它是該登錄請求期間存在。 設計會話控制器:使用Devise Failure App methodology
創建自定義應用程序的故障中所示上面的鏈接
class SessionsController < Devise::SessionsController
def new
flash[:notice] = session.delete(:registration_flash) if session[:registration_flash]
super
end
end
爲什麼不只是將默認設計的閃光消息更改爲您希望消息說的任何內容?您可以編輯devise.en.yml
文件中的Flash消息。我認爲你正在尋找一個正在registrations
signed_up_but_unconfirmed
更新@ rigyt的回答最新色器件。
的lib/devise_failure.rb:
def respond
if http_auth?
http_auth
else
# From original Devise Failure App
store_location!
if flash[:timedout] && flash[:alert]
flash.keep(:timedout)
flash.keep(:alert)
else
flash[:alert] = i18n_message
end
# Store flash temporarily in session because devise strips it
session[:login_flash] = flash.to_hash
redirect_to new_user_session_path
end
end
sessions_controller:
def new
flash_from_session
super
end
def flash_from_session
if session[:login_flash]
session[:login_flash].each do |arr|
flash[arr.first] = arr.last
end
session.delete(:login_flash)
end
end
這將設置如預期的那樣閃爍,從會話中刪除。我也發現它適用於關鍵的cacheable_flash
任何你不想重寫控制器的原因?這是正確的解決方案,只需更改after_sign_up_path_for即可。 – Leito 2013-02-21 19:21:20
好的,會做的謝謝 – rigyt 2013-02-23 11:16:19