Ruby Rails 2.3.5 Flash挂起

时间:2011-05-27 05:32:22

标签: ruby-on-rails ruby

我一直在读取flash [] =在rails中工作的方式,并了解当你redirect_to时,使用flash [...] = ...,如果你正在渲染分配后的动作,然后flash.now [...] ...;然而,我的应用程序的闪存无限期地持续存在,在会话期间从未真正消失。

这个问题是假设的。如果我有控制器,

class MyController < ApplicationController
  def index
    if my_cond 
      flash.now[:notice] = "Your condition is true"
    else
      flash[:notice] = "Your condition isn't true"
      redirect_to some_other_rendering_action
    end
  end
end

如果我重定向这次,那么下次我重定向时,让我们说通过点击连接到某个重定向到另一个渲染的动作的链接,但保持未修改的闪存,然后它渲染闪光。问题是这种情况无限期发生,甚至在一次重定向后都没有结束。

您如何建议排除此问题?该应用程序可能是35k行,并且已经被清洗以遵循flash和flash.now解决方案建议随处可见,所以我们在哪里看?

rails 2.3.5高容量网站,apache / mongrel

添加信息:

闪光灯也在会议中持续存在。

flash: !map:ActionController::Flash::FlashHash 
  :notice: You must be signed in to view this page.

1 个答案:

答案 0 :(得分:1)

我建议您查找flash.keep次来电,如果您没有运气并希望摆脱这种行为,请在flash.discard

中添加一个调用ApplicationController的after_filter
class ApplicationController < ActionController::Base
  after_filter :discard_flash
  private
  def discard_flash
    flash.discard
  end
end