tetiross
tetiross

Reputation: 192

Get all data from session rails

During execution of the web app it stores values in the session. I know that I can get value from it by session[:some_name]. But I need to get all the values from it, preferable in hash. Is there any way to do it? Thanks.

Upvotes: 3

Views: 6855

Answers (2)

Pascal
Pascal

Reputation: 8646

Session is not a hash but mimics hash.

You can use keys and [] to access all elements:

session.keys.each do |key|
  p "#{key} => #{session[key]}"
end

or use to_hash

Upvotes: 1

ksarunas
ksarunas

Reputation: 1227

You can use a method to_hash

session.to_hash

Upvotes: 17

Related Questions