CacheableFlash
Note: This fork (github.com/up_the_irons/cacheable-flash/tree/master) of cacheable-flash aims to be a drop-in replacement for the original cacheable-flash (by Pivotal) but uses JQuery instead of Prototype.
ruby script/plugin install git://github.com/up_the_irons/cacheable-flash.git
This plugin enables greater levels of page caching by rendering flash messages from a cookie using JavaScript, instead of in your Rails view template. Flash contents are converted to JSON and placed in a cookie by an after_filter in a controller.
To use, include the CacheableFlash module in your controller. It’s all or none on the actions in your controller, so you can’t mix JS and HTML display of your flash message in a controller. No other modifications to the controller are needed. You will need to add divs and some javascript to your view or layout templates to render the flash in the browser.
Note that the cookie holding the flash messages is removed as the page is displayed, so a refresh will clear the flash message (just as happens normally).
class MyController < ActionController::Base
include CacheableFlash # ...
end
<div id="error_div_id" class="flash flash_error" display="none" ></div> <div id="notice_div_id" class="flash flash_notice" display="none"></div> <script type="text/javascript"> Flash.transferFromCookies(); Flash.writeDataTo('error', $('#error_div_id')); Flash.writeDataTo('notice', $('#notice_div_id')); </script>