LoginSignup
29
23

More than 5 years have passed since last update.

sessionの中に何があるか知りたい。そんな時はto_hashメソッドを使おう。 Rails

Last updated at Posted at 2016-02-23

sessionの中に何があるか知りたい。
そんな時はto_hashメソッドで簡単に取得できる。

session.to_hash
=> {"session_id"=>"id id id id id id id id id",
"warden.user.user.key"=>[[4319], "key key key key key key"],
"_csrf_token"=>"token token token token token token token token"}

keysメソッドを使えばこれらのkeyだけを配列で取り出せる。

session.keys
=> ["session_id", "warden.user.user.key", "_csrf_token"]
29
23
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
29
23