sinatra-flash icon indicating copy to clipboard operation
sinatra-flash copied to clipboard

Be careful when using the 'shotgun' gem

Open alssndro opened this issue 11 years ago • 7 comments

For anyone else who made this oversight while using Shotgun, be warned that sinatra-flash appears as though it isn't working, but really it is.

I'm assuming this is because Shotgun reloads the entire Sinatra app on each request, so sessions weren't working as they would normally.

So don't use shotgun while testing, use webbrick/unicorn/any other server.

Hopefully this saves someone else a lot of time!

P.S Maybe worth mentioning in the README somewhere?

alssndro avatar Feb 25 '14 18:02 alssndro

"Hopefully this saves someone else a lot of time!"

Yes, saved me!

rchampourlier avatar Mar 06 '14 05:03 rchampourlier

You saved me whatever I was about to spend after an evening and a morning of wondering what on Earth was happening to my brain. Thank you!

fetmar avatar Aug 09 '14 18:08 fetmar

:laughing: I can't believe I felt into this. Thanks for letting the issue open so dumb guys like me can appreciate your remark.

josemotanet avatar Oct 10 '14 10:10 josemotanet

Does anyone know why this is happening? It's not obvious to me that merely reloading the app on each request should cause this problem. The flash content is stored in a session cookie, which will be sent back to the app on the next request. The fact that the app was reloaded in between requests should not break anything.

odigity avatar Sep 27 '15 20:09 odigity

I think that, because shotgun reloads the entire app (does it spawn a new one? I'm not sure), the cookies on the server side are lost since it's the one that issues those cookies in the first place; at least, regarding flash messaging. Only when the HTTP response is returned, the cookie is stored. Because the process is interrupted in each request, redirection and message passing fail.

josemotanet avatar Sep 27 '15 20:09 josemotanet

Thank you for this. I was going a little crazy wondering why the flash hash was empty in my view!

gnfisher avatar Apr 20 '16 18:04 gnfisher

Here's workaround that worked for me. Just add set :session_secret, "something" to your app.

inem avatar Nov 06 '17 17:11 inem