This project is archived and is in readonly mode.

#1792 ✓resolved
Niels Ganser

flash.use should return values which it marked as (un)used

Reported by Niels Ganser | January 23rd, 2009 @ 08:18 PM | in 3.0.2

Motivation

I found myself repeating


flash_content = flash[:whatever]
# ... 
flash.discard(:whatever)

in some of my applications.

One good example would be setting e.g. flash[:info] = "Foobar successfully deleted" in a destroy action which normally redirects to an index action. We'd normally want to display that message in index.erb.html.

However, when responding to an AJAX request, we might want to render destroy.rjs which could e.g. alert(flash[:info]). Without discarding the flash, it would still be present in the next action, which in this case is undesired. Currently a show-and-discard needs to be implemented as outlined above, the patch makes this easier:

What's in the patch?

The patch changes ActionController::Flash::FlashHash.use which is called by FlashHash.discard and FlashHash.keep. After applying the patch, all three functions will return either the single value corresponding to the provided key or itself (the FlashHash).

Any side effects?

I could not find a single line in the codebase in which the return value of either of these three functions is evaluated and all tests pass. So I'd say there aren't any!

Are tests included?

Yes. The included test does properly test the feature but I'm nevertheless not yet sure whether I like it. Feedback welcome!

Let me know what you think. The diff has been generated against the latest commit in master.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Referenced by

Pages