32
30

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.

署名付き cookie を使用する

Posted at

Rails 3.2.2 で確認

署名付き cookie の概要(ざっくり)

署名付き cookie は RAILS_ROOT/config/initializers/secret_token.rb 内の
secret_token を基に cookie 内部の値を暗号化したものを保存させる。

また、署名付きで保存した内容が改ざんされた場合には
InvalidSignature がスルーさせることで、検知が可能となっている。

参考
http://apidock.com/rails/ActionDispatch/Cookies/CookieJar/signed

設定する

hoge_controller.rb
cookies.signed[:hoge] = {
  :value => @user.id,
  :expires => 1.day.from_now,
}

読みだす

hoge_controller.rb
cookies.signed[:hoge] = {
  hoge = cookies.signed[:hoge]
}

削除する

hoge_controller.rb
cookies.delete :hoge
32
30
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
32
30

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?