rails3请求之后,flash内容没有被清除?
flash经常用在controller, 与view中,用来传递与表示信息,通常有修改记录成功,表示一些错误提示内容等。
flash在两个action中传递临时对象,之后,再被清除
理论上是这样的吧,事实上有时你会发现flash内容没有被清除,而且还会在不只一次次的请求中表现出来,现在这样的情况的原因,很简单就是flash的内容没有被清掉了。
如果你想flash的内容这样约定:
(1)flash在两个action之间进行传递,使用flash[] =
(2)flash仅在当前的action中有效,并在当前action执行后,消失,使用flash.now[]=
ruby on rails help pages
"When you need to pass an object to the next action, you use the standard flash assign ([]=). When you need to pass an object to the current action, you use now, and your object will vanish when the current action is done."
总结起来,可以这么使用
flash[:notice] with redirects (e.g. redirect_to :action => 'something')
flash.now[:notice] with renders (i.e. render :action => 'something')
[1]:http://ariejan.net/2007/09/26/flash-not-clearing-after-a-request/
[2]:http://www.rornoob.com/a/rails-flash-not-clearing/