3

As title, I wonder what's the difference between Rails flash.discard and flash.delete.

2 Answers 2

6

@SteveTurczyn is right.

However, flash.delete is only possible to do in versions of rails previous to 3.1.

As of 3.1, flash.delete doesn't work anymore, an alternative might be flash.clear (check out flash.delete(:notice) not working in Rails 3.1 RC?).

You might also want to check: https://apidock.com/rails/v3.0.0/ActionDispatch/Flash/FlashHash/discard

4

flash.delete is immediate. flash.discard will remove the flash at the end of the current action.

So using flash.discard you can still examine the flash contents in the current action.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.