On 2006-07-13, at 15:14 , Martin Emde wrote:

I would expect the opposite of this. A lot of programs may halt a filter chain because a user is not logged in, set the flash to let them know "please login first" and then redirect to the login action which would then display the flash message. If the flash was swept that wouldn't work any longer.


What Isak said. Here's a quick example. Gerenate an app and create a test_controller with the following contents, then visit http:// localhost:3000/test/one and follow the links.

class TestController < ApplicationController
  FLASH = "<pre><%=
    {}.update(flash).to_yaml %><%=
    {}.update(flash.instance_variable_get('@used')).to_yaml %></pre>"

  before_filter :redir, :only => 'skip'

  def one
render :inline => "#{FLASH}1. <%= link_to 'next', :action => 'skip' %>"
  end

  def skip
    render :inline => "#{FLASH}skip"
  end

  def two
render :inline => "#{FLASH}2. <%= link_to 'next', :action => 'three' %>"
  end

  def three
    render :inline => "#{FLASH}3. see..."
  end

  private

  def redir
    flash[:foo] = 'bar'
    redirect_to :action => 'two'
    false
  end
end

The first yaml output is the flash. The second is an internal variable of the flash that keeps track of whether keys have been "used" or not.

During sweep, unused keys are marked used, and kept in the flash, used keys are removed from the flash. That's how keys are kept for one more action, and how you can use flash.keep(:key) to keep a key but not others.

_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core

Reply via email to