Unable to set/use session variables in ruby on rails controller

后端 未结 3 1996
名媛妹妹
名媛妹妹 2021-01-12 08:52

Can somebody tell me the right way to set/use session variables in a ruby on rails application from scratch. I am not able to set/use a session variable in my controller bet

相关标签:
3条回答
  • 2021-01-12 09:08

    Your session cookie settings might be wrong. You should inspect the headers of the response and see what the Set-Cookie header looks like.

    It might have a wrong domain or perhaps your cookie is https only and you're on http.

    The configuration is usually done in some place like config/initializers/session_store.rb

    Myapp::Application.config.session_store :cookie_store, {
      :key =>           '_appname_session_id',
      :path =>          '/',
      :domain =>        nil,   # accepted domain, for example '.example.com'  
      :expire_after =>  nil,   # the session will be expired in X seconds unless active
      :secure =>        false, # if true, cookie is valid only on https
      :httponly =>      true   # if true, javascript can't access the cookie
    }
    
    0 讨论(0)
  • 2021-01-12 09:09

    Try this in config/initializers/session_store.rb

    AppName::Application.config.session_store :cookie_store, key: '_app-name_session'
    
    0 讨论(0)
  • 2021-01-12 09:09

    As a rule of thumb, in rails we create a method in ApplicationController, called current_user In this free RailsCast, you see exactly are you need:

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