New tip
flat | nested
use page caching and still have acccess to flash (1 points)
in rails by jtoy on Mon Apr 17 11:29:03 -0500 2006

If you want to use page caching, but can’t because you will loose the ability to display error and succcess messages, there is a way around this.
You can put your error in javascript so your pages are always cached, only your javascript will change.
You will need to make sure javascript is loaded from the webserver and that the browser isn’t caching your javascript.
In your javascript template have some code like:

<% if flash[:js_notice]  %>

  var js_notice = "<%= flash[:js_notice]  %>"
<% else %>

  var js_notice = null
<% end %>


<% if flash[:js_error]  %>

  var js_error = "<%= flash[:js_error] %>"
<% else %>


function display_flash(){
  if (js_notice){
    var div = document.getElementById("js_notice")
    div.innerHTML =  js_notice
  }
  if (js_error){
    var div = document.getElementById("js_error")
    div.innerHTML = js_error

  }
}
window.onload = display_flash

Then in your layout have this html:
  <div id="js_error"></div>
  <div id="js_notice"></div>

On each new page request, the javascript code will load and check if there are notices or errrors, if there are, then it will place that error on your page in the appropiate div.
RE: use page caching and still have acccess to flash (0 points)
by longdcr on Tue Apr 18 23:09:56 -0500 2006

this is helpful