rails3 flash 清除问题

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/


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值