ruby - How is the `flash` in Rails made global to an application? -
i'm curious how rails achieves this. notice can access flash variable globally in app, isn't prefixed @ or $.
i can see there's method accessing flash , there's initializer set @flash, how can call flash local variable?
session
further apneadiving's answer, flash part of middleware stack (actiondispatch::flash). it's non-persistent session cookie:
--
from the docs:
the flash special part of session cleared each request. means values stored there available in next request, useful passing error messages etc.
much in same way params works (on per request basis), flash variable populated data previous request.
--
middleware
if take apneadiving's comment, you'll see flash created through middleware stack - meaning local nature of variable set particular request (much same params). why can access / set flash message in controller - because it's defined higher "middleware stack" - provides scope appears global
i'm sure apneadiving can explain better me, that's how see it
Comments
Post a Comment