mxgoncharov
mxgoncharov

Reputation: 515

Rails 4 expired CSRF token after some time

I have Rails 4 app. Yesterday, if I had opened a page with a form and my computer stays awake, the next day when I try to submit the form app returns:

500 Internal Error

The log says that authenticity_token is invalid. What can I do?

Upvotes: 2

Views: 422

Answers (1)

atw
atw

Reputation: 5830

In the method of the form that you are submitting, you could place something like:

if response.status == "500"
  redirect_to "enter a suitable url here"
  raise "Your token has expired."
end

This is an extremely basic solution. If it does not work for you there is a nice question and accepted answer here that you can read up on.

Upvotes: 1

Related Questions