重命名Rails中的会话Cookie [英] Rename session cookies in Rails

查看:73
本文介绍了重命名Rails中的会话Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为我希望会话cookie反映URL而不是应用程序名称,所以我想重命名cookie。

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

当前会话cookie名称称为 _APPNAME_session

The current session cookie name is called _APPNAME_session

是否可以将其重命名为 _somethingelse_session

is there a way to rename it to _somethingelse_session?

我看到的时候会看到它的名字

I see the name of it when I do

curl -i <appurl>

我看到

set_cookie = _APPNAME_session=....


推荐答案


  • Rails> = 6.0.0,在config / application.rb中,添加以下行:

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

      config.session_store :cookie_store, key: '_somethingelse_session'
      



    • Rails > = 5.0.0,在config / initializers / session_store.rb中,设置/更改以下行:

    • 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,在config / initializers / session_store.rb中,设置/更改以下行:

    • 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'
      



    • 这篇关于重命名Rails中的会话Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆