注册后(需要确认),我的应用程序重定向到经过身份验证的页面,因此身份验证失败,Devise重定向到登录路径。
由于第二次重定向,我注册后的快闪消息丢失。
在重定向到登录路径之前,在application_controller.rb或助手中,有没有地方可以添加flash.keep
?如果有其他选择的话,我宁愿不去推翻设计控制器。
注册后,在重定向到登录路径之前,我会在会话中存储一条闪存消息(因为用户未确认它是"After_inactive_sign_up_path_for()")
Devise Registrations控制器:
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会话控制器:
class SessionsController < Devise::SessionsController
def new
flash[:notice] = session.delete(:registration_flash) if session[:registration_flash]
super
end
end
使用devise Failure App方法更新@rigyt对最新设计的回答
创建一个自定义故障应用程序,如上面的链接所示。
lib/device_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
这将按预期设置闪烁,并将其从会话中删除。我还发现它与pivotal的cacheable_flash 配合得很好
为什么不将默认的设计flash消息更改为您希望消息所说的内容?您可以在devise.en.yml
文件中编辑闪烁消息。我想你要找的是在registrations
signed_up_but_unconfirmed
下