public
Description: Gets the Rails flash object working with page cacheing.
Homepage:
Clone URL: git://github.com/pivotal/cacheable-flash.git
btakita (author)
Wed Jun 25 01:01:27 -0700 2008
commit  1921711f722f0a9f4ebbf0b6e6f95ec645dcd9fc
tree    25f89956cc0c9cd5ba4d9798a0a7e8eddea507ed
parent  1dd9bfe8111bac16afc4bb37ff528943371ead5d
cacheable-flash / lib / cacheable_flash.rb
100644 21 lines (17 sloc) 0.46 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module CacheableFlash
  def self.included(base)
    base.after_filter :write_flash_to_cookie
  end
 
  def write_flash_to_cookie
    cookie_flash = cookies['flash'] ? JSON.parse(cookies['flash']) : {}
 
    flash.each do |key, value|
      if cookie_flash[key.to_s].blank?
        cookie_flash[key.to_s] = value
      else
        cookie_flash[key.to_s] << "<br/>#{value}"
      end
    end
 
    cookies['flash'] = cookie_flash.to_json
    flash.clear
  end
end