I have a service that allows a survey to be embedded in a page. This survey makes cross domain ajax calls to my server, from pages hosted wherever.
The service runs on rails 3. I'm trying to store the index of the last question answered in a session. ActiveRecord store is active. The service is hosted on heroku. I've migrated the session table and raked it.
But values are not being saved in the session. Is this a problem that I can't get around, or is it possible to have sessions work in this way?
Here's an illustration of the problem:
Rails.logger.info { "session current stage is #{session[:current_stage]}" }
session[:current_stage] = params[:current_stage].to_i
session[:current_stage] ||= 0
Rails.logger.info { "session current stage is #{session[:current_stage]}" }
output looks like this:
session current stage is 0
session current stage is 1
Next time it runs (after session value is 1) :
session current stage is 0
session current stage is 2
Or is it just that my sessions aren't working properly, without regard to cross-domain issues?
Just a quick addition : it appear that a unique session is created each time the server is hit, and not retrieved next time. It treats each call as a new, 开发者_如何学Pythonunprecedented event. I assume this is a by-product of the cross domainery I'm up to. Any solutions?
Apologies for the delay replying – cookies got wiped out and lost track of this question.
I'm using cross-domain calls via jQuery ajax calls, and the connections work great. I'm calling an initialization routine at page load that calls the remote server and gets a JSON object that it uses to assemble a questionnaire that runs in the browser, sending the results back to the server. It has a series of codes embedded in the JSON that eliminates the need for sessions. But when the user changes pages, I need the server to know that when the next page gets the init call, that it's a connection it has already seen.
I'm using ActiveRecord sessions. I can see these accumulating in the sessions table, and it appears that each new connection creates a new session. These connections are almost all via the ajax connections.
I'm writing cookies via a script embedded on the page that also connects to the remote service, which suggests a kind of roll-your-own persistence mechanism – obtain a key from the server, and then check for it. I could probably do IP checks on the server side to sew what now are separate sessions together, I suppose...
精彩评论