25
25

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.

rails4でのcookieの設定・取得

Posted at

Rails4でのCookieの利用方法を調べたのでついでにメモしておく。

署名無しCookieの場合

  • 設定
cookie["Cookie名指定"] = "値"
cookies[:hoge3] = "hoge3"
  • 取得
cookies["Cookie名指定"]
cookies[:hoge3]

署名ありCookieの場合

  • 設定
cookie.signed["Cookie名指定"] = "値"
cookie.signed[:abc] = {:value => "abc", :expires => 1.year.from_now } #←このようにexpireなども設定できる
  • 取得
cookies.signed["Cookie名指定"]
cookies.signed[:abc]
cookies["Cookie名指定"] #← これでも取れるが暗号化されたままの値になる

25
25
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
25
25

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?