Rails gracefully handle timed out sessions?

ruby, ruby-on-rails

Solution

At your `ApplicationController`:

rescue_from ActionController::InvalidAuthenticityToken do 
  redirect_to some_path
end

Problem

Using rails 4, ruby 2. I've set a timeout time of 30 minutes for my cookie session in the rails config. The problem is if I go to a form, let the session timeout, and then submit the form, I get this `ActionController::InvalidAuthenticityToken` error. How do I gracefully handle this error in rails? Say, redirect to login screen?

Original source