title: Setting Session Variables with AJAX and Rails when appcache is present
body: <p>Have an ajax call to "updateUser" which does this:</p>
  
  <pre><code>puts session[:user_id]
  user = User.find(params[:user_id])
  if user
    session[:user_id] = user.id
    session[:user_name] = user.first_name + " " + user.last_name
    puts session[:user_id]
    render text =&gt; "Success.
  end
  </code></pre>
  
  <p>The first <code>puts</code> shows the <strong>original</strong> user_id and the second shows the <strong>new</strong> user_id, so it would appear to be working properly.  However, when I navigate to another page, all the session information is still that of the <strong>original</strong> user_id.  What have I done wrong?</p>
  
  <p>I have a feeling it has something to do with the local session cookie not being updated.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Definitely has something to do with caching.  I can go to the page, clear the browser cache (am using Chrome as my browser), then run the ajax call and it works properly once.  After that I am locked in to the (new) old user again.</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>Looks like it is something specifically to do with html5 application-cache. If I kill the appcache or run the script from a page that does not include <code>manifest</code> it works just fine.   Still can't get it working properly on the cached page.</p>
  
  <p>The same session id is being sent to the server from the cached page as the non-cached page, and the response headers are identical.  But each request from the locally cached page causes the server to start with old session information.</p>