Skip to content

Rails flash working with page caching. Forked to work with JQuery instead of Prototype.

Notifications You must be signed in to change notification settings

debprado/cacheable-flash

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Installation

ruby script/plugin install git://github.com/up_the_irons/cacheable-flash.git

Description

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.

Usage

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).

Example Controller

class MyController < ActionController::Base

include CacheableFlash
# ...

end

Example Template Markup

<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>

About

Rails flash working with page caching. Forked to work with JQuery instead of Prototype.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 82.3%
  • Ruby 17.7%