Search code examples
ruby-on-railssessionhashhash-of-hashes

How to access a multidimensional hash session?


I am using the session method of Ruby on Rails so that I have a session[:user_params] hash like this:

password_confirmation: "test"
password: test
email: [email protected]

I can access that simply using the syntax session[:user_params] in my view file.

Now I want access only the 'email' parameter, but trying to use session[:user_params][:email], I get always an empty value. How to access this value?


Solution

  • You might try session[:user_params]['email']. Off hand I'm not sure if Rails will serialize/deserialize the entire session hash as a HashWithIndifferentAccess or not.