views:

22

answers:

2

I am trying to make use of session data in my application and for some reason I don't have something setup right.

The code:

session[:key] = some_value 

Generates the following error:

The error occurred while evaluating nil.[]

Other controllers don't have an issue with the session, so I am guessing I missed some basic configuration thing somewhere.

A: 

It looks like the session variable is nil which makes me think the framework couldn't set it for one of these reasons:

  1. Browser passed in no cookie for the session
  2. Browser passed in a cookie but it didn't match anything the server expected

It was stated that some controllers work. Did something have the opportunity to create a session for the user before those controllers ran?

Evan
See my comments on original post
Bill Leeper
A: 

Ok, I think I got it figured out now. I had a slightly more complex situation that my example. I actually had the following:

session[:chat_history][chat.from.id] ||= []

So I had an error with double array. I added the following:

session[:chat_history] ||= []

Problem was the first time I did this, I put it in a before_filter method. Apparently the session object is nil in the before_filter method, at least the way I have my application setup.

So I moved the initializer to the methods that actually access the session and life is good again.

Bill Leeper