How to set a multidimensional array in a rails session

I am trying to do something like this:

session[:continent][:filter] = params[:filter]

but it does not work, I got this error:

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]=
+5
source share
1 answer

You need to initialize the [: continent] session first to be a hash. Try the following:

session[:continent] ||= {}
session[:continent][:filter] = params[:filter]
+13
source

All Articles