Note that there are some explanatory texts on larger screens.

plurals
  1. POflash reappears on refresh
    text
    copied!<p>I show flash messages in my rails app using javascript (essentially every flash message is an overlay div).</p> <p>The following partial is included in my main layout file and it takes care of displaying the flash. I notice that if I refresh a page, the same flash message keeps reappearing. Anyway to get rid of this? I know I can call a flash.discard though not sure what's the best place to do that and I don't want another controller call just to discard the flash.</p> <pre><code>&lt;% if !flash.nil? %&gt; &lt;% if flash[:notice] %&gt; &lt;script type="text/javascript"&gt; //&lt;![CDATA[ showFlash("&lt;%= flash[:notice] %&gt;", "flash-notice"); //]]&gt; &lt;/script&gt; &lt;% end %&gt; &lt;% if flash[:success] %&gt; &lt;script type="text/javascript"&gt; //&lt;![CDATA[ showFlash("&lt;%= flash[:success] %&gt;", "flash-success"); //]]&gt; &lt;/script&gt; &lt;% end %&gt; &lt;% if flash[:error] %&gt; &lt;script type="text/javascript"&gt; //&lt;![CDATA[ showFlash("&lt;%= flash[:error] %&gt;", "flash-error"); //]]&gt; &lt;/script&gt; &lt;% end %&gt; &lt;% end %&gt; function showFlash(msg, tp) { if ($('#flash_messages_container').length &gt; 0) { flashAnimatedHide(); } var flashContainer = $("&lt;div id='flash_messages_container' class='flash-messages " + tp + " '&gt;&lt;/div&gt;"); flashContainer.prepend("&lt;div id='flash_messages_content'&gt;" + msg + "&lt;span class='go-right sprite close' id='close_flash'&gt;&lt;/span&gt;&lt;/div&gt;"); $('body').prepend(flashContainer); flashContainer.animate({ opacity : .1 }, '500', function(){ flashContainer.css('opacity', 1) }) $('body').css('margin-top', flashContainer.outerHeight()); $('#close_flash').click(function() { flashAnimatedHide(); $('body').css('margin-top', '0'); }); } </code></pre> <p>UPDATE</p> <p>I suspect this is happening since I starting using etags for cient side and reverse proxy caching. So I guess the refresh is simply loading the cached page, which contains the flash messages in the flash container. So how do people discard flash when caching is enabled?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload