gpt4 book ai didi

ruby-on-rails - 设计重定向到登录路径时如何 flash.keep

转载 作者:行者123 更新时间:2023-12-03 22:39:37 24 4
gpt4 key购买 nike

注册后,需要确认,我的应用程序重定向到经过身份验证的页面,因此身份验证失败,Devise 重定向到登录路径。

由于第二次重定向,我在注册后的 flash 消息丢失了。

有什么地方可以添加 flash.keep在重定向到登录路径之前,在 application_controller.rb 还是在助手中?如果有替代方案,我不希望为此覆盖设计 Controller 。

最佳答案

注册后,在重定向到登录路径开始之前,我在 session 中存储了一条 flash 消息(因为用户未确认它是“after_ 非事件 _sign_up_path_for()”)

设计注册 Controller :

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

然后,如果在登录请求期间出现此消息,我将显示此消息。
设计 session Controller :
class SessionsController < Devise::SessionsController
def new
flash[:notice] = session.delete(:registration_flash) if session[:registration_flash]
super
end
end

关于ruby-on-rails - 设计重定向到登录路径时如何 flash.keep,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15010124/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com