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.

3
  • It would be helpful to see the code that's generating the error. You say 'other controllers' without indicating what controller this line is in and how it's configured. Commented Jun 16, 2010 at 3:44
  • I jumped the gun a bit. The real issue is that there is a post method being called from javascript and in that method, the session is not valid. Commented Jun 16, 2010 at 3:50
  • The plot thickens even more. This is only happening in Chrome, works fine in firefox Commented Jun 16, 2010 at 3:56

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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?

1 Comment

See my comments on original post

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.