Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a multidimentional array in session with rails

I am trying to do something like this :

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

but it doesn't 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.[]=
like image 868
Sebastien Avatar asked Oct 04 '11 15:10

Sebastien


1 Answers

You need to initialise session[:continent] to be a Hash first. Try this:

session[:continent] ||= {}
session[:continent][:filter] = params[:filter]
like image 188
Olly Avatar answered Nov 09 '22 10:11

Olly