Log all user flash messages #2808

This commit is contained in:
Priit Tark 2015-07-23 13:30:05 +03:00
parent 17af1218b5
commit e3a8604ec4
2 changed files with 23 additions and 1 deletions

View file

@ -8,7 +8,7 @@ end if Bundler::VERSION < '2'
source 'https://rubygems.org' source 'https://rubygems.org'
# core # core
gem 'rails', '4.2.3' gem 'rails', '4.2.3' # when update, all initializers eis_custom files needs check/update
gem 'iso8601', '~> 0.8.2' # for dates and times gem 'iso8601', '~> 0.8.2' # for dates and times
gem 'hashie-forbidden_attributes', '~> 0.1.1' gem 'hashie-forbidden_attributes', '~> 0.1.1'

View file

@ -0,0 +1,22 @@
module ActionDispatch
class Flash
def call(env)
@app.call(env)
ensure
session = Request::Session.find(env) || {}
flash_hash = env[KEY]
if flash_hash && (flash_hash.present? || session.key?('flash'))
session["flash"] = flash_hash.to_session_value
Rails.logger.info "FLASH: #{Time.now.to_s(:db)} #{session['flash']['flashes'].inspect}" if session['flash']
env[KEY] = flash_hash.dup
end
if (!session.respond_to?(:loaded?) || session.loaded?) && # (reset_session uses {}, which doesn't implement #loaded?)
session.key?('flash') && session['flash'].nil?
session.delete('flash')
end
end
end
end