Rails 4 session.id occasionally nil

前端 未结 1 1105
醉话见心
醉话见心 2020-12-21 02:08

I\'m running a simple website on Heroku and I\'m noticing something strange occurring when I\'m running the app. It appears that approximately 50-60% of my users are report

相关标签:
1条回答
  • 2020-12-21 02:48

    I found the answer, it looks like Rails is trying to be efficient by only creating a session if there is something to store. So accessing the session.id without storing something doesn't return consistent results.

    You need to force the session to be created by storing something in it.

    TLDR: Add this somewhere before you access the session ID.

    session[:foo] = "bar"
    

    Source: http://www.gani.com.au/2013/08/force-session-creation-in-rails/

    0 讨论(0)
提交回复
热议问题