如何诊断消失的Flash消息?

问题描述 投票:0回答:1

我像往常一样创建了一条记录,并且byebug已经确认已创建了flash消息。但是当我被重定向时,我看不到任何闪光。在某些情况下闪存会被删除吗?我该如何解决?我使用自定义构建的omniauth授权方法。如果这导致问题,我该如何进一步调查?

[262, 271] in /home/jacekp/.rvm/gems/ruby-2.4.5@rails4qc_charts/gems/actionpack-4.2.10/lib/action_dispatch/middleware/flash.rb
   262:       session    = Request::Session.find(env) || {}
   263:       flash_hash = env[KEY]
   264: 
   265:       if flash_hash && (flash_hash.present? || session.key?('flash'))
   266:         session["flash"] = flash_hash.to_session_value
=> 267:         env[KEY] = flash_hash.dup
   268:       end
   269: 
   270:       if (!session.respond_to?(:loaded?) || session.loaded?) && # (reset_session uses {}, which doesn't implement #loaded?)
   271:         session.key?('flash') && session['flash'].nil?
(byebug)  session["flash"] 
{"discard"=>[], "flashes"=>{"notice"=>"Sample was successfully created."}}
(byebug) n

[266, 275] in /home/jacekp/.rvm/gems/ruby-2.4.5@rails4qc_charts/gems/actionpack-4.2.10/lib/action_dispatch/middleware/flash.rb
   266:         session["flash"] = flash_hash.to_session_value
   267:         env[KEY] = flash_hash.dup
   268:       end
   269: 
   270:       if (!session.respond_to?(:loaded?) || session.loaded?) && # (reset_session uses {}, which doesn't implement #loaded?)
=> 271:         session.key?('flash') && session['flash'].nil?
   272:         session.delete('flash')
   273:       end
   274:     end
   275:   end

experiment

我在.rvm / gems / ruby​​-2.4.5 @ rails4qc_charts / gems / rack-1.6.11 / lib / rack / request.rb中插入了byebug

  def session; byebug ;        @env['rack.session'] ||= {}              end

看看发生了什么,并尝试了一个在会话中设置flash的页面。我正在考试

(byebug)@env ['rack.session']。钥匙

并没有找到任何能给我一些线索的东西。

ruby-on-rails flash-message
1个回答
0
投票

经过几个小时的调试后,我更好地了解了谷歌的用途并发现了这篇文章:Rails flash missing from session

所以我在config / application.rb中注释掉了这个错误

config.middleware.use ActionDispatch::Cookies # Required for all session management
#config.middleware.use ActionDispatch::Session::CookieStore, config.session_options

在评论第二行之前,我有消失的闪存错误。

© www.soinside.com 2019 - 2024. All rights reserved.