Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename session cookies in Rails

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=....
like image 955
Nick Ginanto Avatar asked Dec 02 '12 14:12

Nick Ginanto


1 Answers

  • 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'
    
like image 84
julp Avatar answered Sep 22 '22 20:09

julp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!