Skip to content

Commit 85969c7

Browse files
committed
move flash hash access to methods on the request object
1 parent b3f5d3c commit 85969c7

File tree

1 file changed

+11
-2
lines changed
  • actionpack/lib/action_dispatch/middleware

1 file changed

+11
-2
lines changed

actionpack/lib/action_dispatch/middleware/flash.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ class Request < Rack::Request
88
def flash
99
@env[Flash::KEY] ||= Flash::FlashHash.from_session_value(session["flash"])
1010
end
11+
12+
def flash=(flash)
13+
@env[Flash::KEY] = flash
14+
end
15+
16+
def flash_hash # :nodoc:
17+
@env[Flash::KEY]
18+
end
1119
end
1220

1321
# The flash provides a way to pass temporary primitive-types (String, Array, Hash) between actions. Anything you place in the flash will be exposed
@@ -263,14 +271,15 @@ def initialize(app)
263271
end
264272

265273
def call(env)
274+
req = ActionDispatch::Request.new env
266275
@app.call(env)
267276
ensure
268277
session = Request::Session.find(env) || {}
269-
flash_hash = env[KEY]
278+
flash_hash = req.flash_hash
270279

271280
if flash_hash && (flash_hash.present? || session.key?('flash'))
272281
session["flash"] = flash_hash.to_session_value
273-
env[KEY] = flash_hash.dup
282+
req.flash = flash_hash.dup
274283
end
275284

276285
if (!session.respond_to?(:loaded?) || session.loaded?) && # (reset_session uses {}, which doesn't implement #loaded?)

0 commit comments

Comments
 (0)