Module: CacheableFlash
- Defined in:
- lib/cacheable_flash/railtie.rb,
lib/cacheable_flash.rb,
lib/cacheable_flash/engine.rb,
lib/cacheable_flash/version.rb,
lib/generators/cacheable_flash/install/install_generator.rb
Overview
Add cacheable flash JS to defaults for Rails < 3.1 (not needed with asset pipeline)
Defined Under Namespace
Classes: Engine, InstallGenerator, Railtie
Constant Summary collapse
- VERSION =
"0.2.5"
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
15 16 17 18 |
# File 'lib/cacheable_flash.rb', line 15 def self.included(base) #base must define around_filter, as in Rails base.around_filter :write_flash_to_cookie end |
Instance Method Details
#write_flash_to_cookie ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/cacheable_flash.rb', line 20 def yield if block_given? = if ['flash'] begin JSON(['flash']) rescue {} end else {} end flash.each do |key, value| if [key.to_s].blank? [key.to_s] = value.kind_of?(Numeric) ? value.to_s : value else [key.to_s] << "<br/>#{value}" end end # Base must define cookies, as in Rails ['flash'] = .to_json.gsub("+", "%2B") # Base must define flash, as in Rails flash.clear end |