`

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/


 

 

分享到:
评论

相关推荐

    rails3教程

    Rails3教程系列 DRY(Dont Repeat Yourself) DRY(Dont Repeat Yourself) DRY(Dont Repeat Yourself) DRY(Dont Repeat Yourself) DRY(Dont Repeat Yourself) DRY(Dont Repeat Yourself) DRY(Dont Repeat Yourself) DRY...

    Rails 3 in Action

    Rails 3 in Action 2011年9月新鲜出炉,针对最新的Rails 3.1进行说明

    rails金典教材3本

    Ruby+on+Rails+3+Tutorial.pdf 应用Rails进行敏捷Web开发第4版.pdf (Agile Web Development with Rails) Rails.Recipes.Rails.3.Edition.pdf

    RVM_Ruby1.9.3_Rails3(2-Ruby on Rails3安装配置)

    Windows7_Cygwin_Git_RVM_Ruby1.9.3_Rails3_MongoD B_Nginx_Unicorn_Rspec_Guard_Spork(2-Ruby on Rails3 安装配置

    Rails3消息队列系统 Sidekiq

    Rails3消息队列系统 Sidekiq

    rails3文档

    rails3的英文文档

    Rails3的ActiveRecord 查询API.doc

    Rails3的ActiveRecord 查询API.doc

    turbo-sprockets-rails3, 加速你的Rails 3资产.zip

    turbo-sprockets-rails3, 加速你的Rails 3资产 用于 Rails 3.2.x的涡轮链轮 通过只根据源文件的哈希来重新编译已经更改的资产,从而加快 Rails 3 rake assets:precompile的速度只编译一次以生成指纹和非打印的资产...

    Rails3常用命令行命令

    rails常用命令,例如新建rails项目,新建controller、model 等等

    centOS Rails3环境搭建

    3 rails # gem install rails -v=2.3.11 4 passenger # gem install passenger passenger-install-apache2-module 安装完成后按照提示将下面的内容添加到etc/httpd/httpd.conf LoadModule pa

    The Rails 3 Way(2nd)

    The Rails™ 3 Way is a comprehensive resource that digs into the new features in Rails 3 and perhaps more importantly, the rationale behind them. —Yehuda Katz, Rails Core The Bible for Ruby on ...

    cacheable-flash, 获取处理页cacheing的Rails Flash 对象.zip

    cacheable-flash, 获取处理页cacheing的Rails Flash 对象 是一个新的希望这里 gem 不再被维护。 请考虑切换到 github.com/leonid-shevtsov/unobtrusive_flash 。这么长的时间,感谢你 ! CacheableFlash 描述这个...

    ruby on rails 3 tutorial.pdf

    ruby on rails开发的初学者很适合的工具书,易上手,很实用,

    The Rails3 Way, 2nd Edition

    The Rails™ 3 Way is the only comprehensive, authoritative guide to delivering production-quality code with Rails 3. Pioneering Rails expert Obie Fernandez and a team of leading experts illuminate ...

    [Rails] Crafting Rails Applications (英文版)

    This pioneering book is the first resource that deep dives into the new Rails 3 APIs and shows you how use them to write better web applications and make your day-to-day work with Rails more ...

    基于java的开发源码-Rails3消息队列系统 Sidekiq.zip

    基于java的开发源码-Rails3消息队列系统 Sidekiq.zip 基于java的开发源码-Rails3消息队列系统 Sidekiq.zip 基于java的开发源码-Rails3消息队列系统 Sidekiq.zip 基于java的开发源码-Rails3消息队列系统 Sidekiq.zip ...

    jquery-rails, 一个 gem,用于自动使用jQuery和 Rails 3.zip

    jquery-rails, 一个 gem,用于自动使用jQuery和 Rails 3 railsjQuery 面向 Rails 如此伟大。这里 gem 提供:jQuery 1.7.2jQuery UI 1.8.18 ( 仅适用于 javascript )jQuery UJS适配器assert_select_j

    rails3入门指南

    ruby on rails文档,rails3入门指南

    rails 2.3.2离线安装rails 2.3.2离线安装

    rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails ...

Global site tag (gtag.js) - Google Analytics