Sha256: 7a0df8c91143ae400a2be6bf3a7af5422a9f30935cf6dbfb3a0e7e1e3e8cc706

Contents?: true

Size: 1.5 KB

Versions: 2

Compression:

Stored size: 1.5 KB

Contents

# Unobtrusive flash messages for Rails

Ever got tired of pages that can't be cached because they contain flash messages?

Ever got tired of writing custom code to handle flash messages passed in AJAX responses?

Here comes the solution.

`unobtrusive_flash` takes your flash messages for the backend and automagically passes them to the frontend via
HTTP cookies. This works with both regular page loads and AJAX requests, does not tamper with the page body and requires
about 3 extra lines of code in your app - how's that for unobtrusive?

You can pass up to 4K of text into flash this way, and you don't need to worry about cookie size since they are
cleared immediately upon rendering.

Tested and fully functional in: 

* Internet Explorer 8
* Firefox 4b7
* Chrome 7
* Safari 5
* Opera 10.6
* *please let me know if it works in firefox 3 and ie 6, 7*

## Requirements

* Rails 2.3 or 3
* jQuery (maybe I'll make it agnostic in the future)

## Usage

1. Add the gem to your Rails app.
2. Run `script/generate unobtrusive_flash` or `rails g unobtrusive_flash:install`
3. Add the following to the controllers that generate flash messages (or better, to the `ApplicationController`):

        after_filter :prepare_unobtrusive_flash
 
4. Include `unobtrusive_flash.css` and `unobtrusive_flash.js` in your layouts. No custom markup is needed.
5. Remove existing flash rendering code from your layouts.
6. That's all! You can also edit the generated CSS/JS to your liking.

* * *

© 2010 Leonid Shevtsov, released under the MIT license

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
unobtrusive_flash-0.0.2 README.markdown
unobtrusive_flash-0.0.1 README.markdown