SFEley/sinatra-flash

Be careful when using the 'shotgun' gem

Opened this issue ยท 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?

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

Yes, saved me!

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!

๐Ÿ˜† I can't believe I felt into this. Thanks for letting the issue open so dumb guys like me can appreciate your remark.

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.

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.

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

inem commented

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