*I posted this to the talk mailing list
<https://groups.google.com/forum/#!topic/rubyonrails-talk/ulfHtDvtNM4> but
got no response, not sure if this list is more suitable.*

As the subject suggests, I'm not sure if this is a bug or a feature.

If I have an action that sets something in the flash and *redirects to an
action* (to pre-empt the "flash.now" responses) that renders something
but *does
not touch the flash at all* then the values will remain in the flash for
following requests to pick up. This could potentially be an infinite number
of requests later if none of the requests in between touch the flash.

I believe this is because Request.flash is lazily loaded
<https://github.com/rails/rails/blob/e6d8f435a921dce360bce9faae7dabaf753d4d23/actionpack/lib/action_dispatch/middleware/flash.rb#L9>
but
only swept (as a side effect of to_session_value
<https://github.com/rails/rails/blob/e6d8f435a921dce360bce9faae7dabaf753d4d23/actionpack/lib/action_dispatch/middleware/flash.rb#L103>)
if it *has been* lazy loaded
<https://github.com/rails/rails/blob/e6d8f435a921dce360bce9faae7dabaf753d4d23/actionpack/lib/action_dispatch/middleware/flash.rb#L269>
.

Touching the flash in anyway (even without using it) will produce the
behaviour I expect of the flash being cleared in the request following the
redirect and so no further requests being able to access it. This means I
can use an after_action or similar to ensure it is always loaded and get
the behaviour I expect.

Is the current behaviour expected?

If it is, I have a work around and hopefully this will exist on Google for
other people who expect it to work as I do. If it isn't, I'm happy to look
into it and create a pull request.

Cheers,
Garry

*Garry Shutler*
@gshutler <http://twitter.com/gshutler>
gshutler.com

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to