Sha256: f806e9f1986248548aceac1d9e10e8564c2c02f4313b266d25c4bffb5cef8e86

Contents?: true

Size: 614 Bytes

Versions: 5

Compression:

Stored size: 614 Bytes

Contents

# http://github.com/pivotal/cacheable-flash

require "json"

module CacheableFlash
  def self.included(base)
    base.prepend_around_action :write_flash_to_cookie
  end

  def write_flash_to_cookie
    yield self

    cookie_flash = begin
      JSON.parse(cookies["flash"] || "{}")
    rescue JSON::ParserError
      {}
    end

    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}" # TODO should be an array
      end
    end

    cookies['flash'] = cookie_flash.to_json
    flash.clear
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
adva-0.1.4 lib/rails_ext/action_controller/cacheable_flash.rb
adva-0.1.3 lib/rails_ext/action_controller/cacheable_flash.rb
adva-0.1.2 lib/rails_ext/action_controller/cacheable_flash.rb
adva-0.1.1 lib/rails_ext/action_controller/cacheable_flash.rb
adva-0.1.0 lib/rails_ext/action_controller/cacheable_flash.rb