8

since I'd like the session cookie to reflect the url and not the app name, I'd like to rename the cookies..

The current session cookie name is called _APPNAME_session

is there a way to rename it to _somethingelse_session?

I see the name of it when I do

curl -i <appurl>

I see

set_cookie = _APPNAME_session=....
Nick Ginanto
  • 31,090
  • 47
  • 134
  • 244

1 Answers1

22
  • Rails >= 6.0.0, in config/application.rb, add the following line:

    config.session_store :cookie_store, key: '_somethingelse_session'
    
  • Rails >= 5.0.0, in config/initializers/session_store.rb, set/change the following line:

    Rails.application.config.session_store :cookie_store, key: '_somethingelse_session'
    
  • Rails < 5.0.0, in config/initializers/session_store.rb, set/change the following line:

    <APPNAME>::Application.config.session_store :cookie_store, key: '_somethingelse_session'
    
julp
  • 3,860
  • 1
  • 22
  • 21
  • 2
    If your using activerecord sesion store you can just write this: `::Application.config.session_store :active_record_store, :key => "_somethingelse_session"` – Johan S Nov 03 '13 at 14:30
  • if you want you can also set `:expire_after`, `secure:`, and `httponly:` while your at it. https://api.rubyonrails.org/v7.0.6/classes/ActionDispatch/Session/CookieStore.html – Chrismisballs Jul 26 '23 at 16:58