3

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

Trantor Liu
  • 8,770
  • 8
  • 44
  • 64

2 Answers2

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

Darme
  • 6,984
  • 5
  • 37
  • 52
Nico Brenner
  • 690
  • 7
  • 11
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.

SteveTurczyn
  • 36,057
  • 6
  • 41
  • 53