Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show the flash message in Rails only once?

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.

like image 571
Martin Petrov Avatar asked Feb 28 '11 13:02

Martin Petrov


2 Answers

You could use

flash.now

Here's a thumb-rule.

In your controller, use flash when you're redirecting and flash.now when rendering.
like image 195
Shreyas Avatar answered Nov 05 '22 06:11

Shreyas


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/

like image 45
Pascal Van Hecke Avatar answered Nov 05 '22 06:11

Pascal Van Hecke