我想做这样的事情:
session[:continent][:filter] = params[:filter]
但它不起作用,我得到了这个错误:
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.[]=
解决方法
您需要首先将会话[:continent]初始化为哈希.试试这个:
session[:continent] ||= {} session[:continent][:filter] = params[:filter]