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

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -