Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7894415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:23:29+00:00 2026-06-03T07:23:29+00:00

In our Rails application, it is common for users to keep multiple browser tabs

  • 0

In our Rails application, it is common for users to keep multiple browser tabs open for hours or days at a time. The problem occurs when in one of these tabs, the user logs out then logs back in (or the session expires and a new session is created).

This causes the CSRF authenticity tokens on all the other tabs to become invalid. If they try to submit any form or make any ajax request on those tabs without refreshing, they will get an error (and in fact get logged out because that is the default Rails behavior when a bad authenticity token is passed).

This behavior is clearly undesirable. I was wondering what people do to gracefully handle situations where a user has a window open to your site but the authenticity token is out of date.

What I don’t want to do is just redirect them to the login page, because then they might lose their work, if for example they have been writng a long blog post or something.

The solution that comes to mind is to have some javascript that either polls the server to check whether the authenticity token has changed, or polls the user’s cookies to check whether the session has changed. I have never heard of anyone doing either of these, so I wanted to see what the community thought.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:23:30+00:00Added an answer on June 3, 2026 at 7:23 am

    First of: logging in/out/in won’t lead to appearing a new csrf-token. It still will be saved in the user’s cookie. Next time it logs in via the same browser it’ll get the same token.

    In latest versions of Rails no errors will be thrown in the case of incorrect token: all the Rails does — just resets the session before passing it to a controller.

    So, update your Rails and you’ll get one pain less.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

By default Rails allows users of our application to input non-utf8 data, such as:
I'm looking at converting our Rails 2.3 application to correctly handle time zones (at
We just found something strange with our rails 3.1.3 app's application.js. The problem is
We're using EngineYard Cloud to deploy our Ruby on Rails application. We are running
I have created a pdf version of our rails application using the Prawn plugin,
Our application allows users to upload javascript, CSS, and HTML files. We need a
Some of the users of our Ruby on Rails app have complained that page
As our Rails application deals with increasing user activity and load, we're starting to
Here's our basic requirements: We have a base Rails application, which is being actively
I have 4 days off and I will use this time to rewrite our

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.