This project is archived and is in readonly mode.
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
-
Niels Ganser January 23rd, 2009 @ 09:25 PM
Here's an alternative, i.e. more extensive, test:
def test_keep_and_discard_return_values flash = ActionController::Flash::FlashHash.new flash.update(:foo => :foo_indeed, :bar => :bar_indeed) [:discard, :keep].each do |method| assert_equal(:foo_indeed, flash.send(method, :foo)) # valid key passed assert_nil flash.send(method, :unknown) # non existant key passed assert_equal({:foo => :foo_indeed, :bar => :bar_indeed}, flash.send(method)) # nothing passed assert_equal({:foo => :foo_indeed, :bar => :bar_indeed}, flash.send(method, nil)) # nothing passed end end
-
Niels Ganser January 23rd, 2009 @ 09:46 PM
Right.. Sorry for the soliloquy. Please review the attached updated patch which features more extensive tests.
I wonder if the test should go someplace else though as it doesn't really fit in with the rest of the file. Any thoughts on this?
-
Pratik May 18th, 2009 @ 07:50 PM
- Assigned user set to josh
-
josh May 25th, 2009 @ 05:28 PM
- State changed from new to open
- Milestone cleared.
-
Repository May 27th, 2009 @ 09:02 PM
- State changed from open to resolved
(from [bb8e5843f32b13e759da51a4713a31b23ebcac6d]) ActionController::Flash::FlashHash.use now returns either the value corresponding to the passed key or itself when no key is passed [#1792 state:resolved]
Signed-off-by: Joshua Peek josh@joshpeek.com
http://github.com/rails/rails/commit/bb8e5843f32b13e759da51a4713a31... -
Repository February 2nd, 2010 @ 10:33 AM
(from [c01014ac1c98a05fe68e652f978dfa9d43f0fc2b]) Modify the behavior of
radio_button_tag
to usesanitize_to_id
for consistency [#1792 status:resolved]Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/c01014ac1c98a05fe68e652f978dfa... -
Jeremy Kemper October 15th, 2010 @ 11:01 PM
- Milestone set to 3.0.2
- Importance changed from to
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
Attachments
Referenced by
- 1792 flash.use should return values which it marked as (un)used (from [c01014ac1c98a05fe68e652f978dfa9d43f0fc2b]) Modify ...
- 1792 flash.use should return values which it marked as (un)used (from [bb8e5843f32b13e759da51a4713a31b23ebcac6d]) ActionC...