I’m making some fairly extensive changes to a Radiant CMS/Ruby on Rails application – upgrading to Radiant 1.* along with a lot of gem changes – and in the process, we’ve begun having problems with maintaining the user session. Normal calls are working fine, but any AJAX calls that come in are finding no active session for the user and creating a new one.
We’re using a cookie-store, so there’s probably something wrong going on there, but I’m not sure what or where to look. Examining the Request headers, it looks like the session cookie is getting passed in the cookie header for the AJAX call. What’s getting passed in the cookie headers looks the same for both types of requests. Yet, when getting the session variable in the controller, a new session is getting created for ajax calls and not for standard http calls.
Any idea what might be going on, or where I should look to debug what’s happening?
The problem is likely that the security token is not getting passed along in the Ajax call and this is causing your authorization gem to logout the user. Here is a way to have the security token passed in all Ajax calls transparently:
app/views/layouts/application.html.erb
Then add the jquery-ujs gem to your Gemfile:
Gemfile
And this line to your application javascript file below the jquery line:
app/assets/application.js
Here is more information about the jquery-ujs gem