pivotal/cacheable-flash — pull request #12 by pedrocarrico (2012-08-03 17:09:37+00:00)
Title: Make Cacheable flash available as a Rack middleware

When setting the flash in a rescue_from the flash messages are not being written to the cookie because the rescue_from will set the flash after write_flash_to_cookie is called (if it is called at all, as it won't be called when the exception occurs before).

For example:

class ApplicationController < ActionController::Base
rescue_from CanCan::AccessDenied do |exception|
redirect_to root_url, :alert => exception.message
end
end

In this case, the flash message from the rescue_from will only be processed in the following request.

Making cacheable flash write the flash to the cookie using a Rack middleware ensures that the flash is written to the cookie after all filters and rescue_from handlers are run.

It works by swapping the ActionDispatch::Flash middleware with its own CacheableFlash middleware. This is optional (and in no way enforced), and serves to avoid unnecessary processing by the ActionDispatch::Flash middleware.

This new approach only applies to Rails 3 and so, developers must explicitly enable it. If they don't, cacheable_flash will work as before - with an around_filter - therefore it will not break existing applications.

We've also changed the README to include this usage.

This pull request is the result of the combined efforts [Telmo Costa](https://github.com/telmofcosta), [Duarte Henriques](https://github.com/dsgh) and myself.