6

Is it possible to show the flash message in rails only once? I mean, when I delete something the flash says "Deleted (undo)", and then if I click a click and then the browser's Back button the message is still there.

Martin Petrov
  • 2,633
  • 4
  • 30
  • 44

2 Answers2

17

You could use

flash.now

Here's a thumb-rule.

In your controller, use flash when you're redirecting and flash.now when rendering.
Shreyas
  • 8,737
  • 7
  • 44
  • 56
  • In the particular case I'm redirecting - from the Show view to the Index. My question is whether the flash message can be removed after you leave the page that has the flash message and then you click the Back button. – Martin Petrov Feb 28 '11 at 13:39
  • I found in this stackoverflow thread that this is related to caching: http://stackoverflow.com/questions/711418/how-to-prevent-browser-page-caching-in-rails – Martin Petrov Feb 28 '11 at 13:46
1

This is probably a generic browser caching problem. You can force your browser to reload a page while hitting the back button by setting some no-cache headers.

You could try this approach: (found after a quick google search, you might want to dig deeper)

http://blog.serendeputy.com/posts/how-to-prevent-browsers-from-caching-a-page-in-rails/

Pascal Van Hecke
  • 4,516
  • 3
  • 19
  • 18