11
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Railsで保存したsessionのcookieを消す方法

11
Posted at

意外とめんどくさかったのでメモ。もちろんブラウザの設定からクッキーを消すこともできるけどそれもブラウザごとに違うし色々めんどくさいのでRails側でやる方法。

まず 「Session 消し方 Rails」とかで検索すると出てくるので

rake db:sessions:clear とか rake tmp:sessions:clear だけど、これじゃ消えない。
エラー画面で reset_session とか session[:user_id] = nil とかもしてみたけど、どうも反映はされないっぽい。

解決策

今見てるViewの controller の該当methodに session.clearって書く。これでOK、ちゃんと消えた。

11
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?