Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - Catch 'Invalid Authenticity Token' exception

I'm currently using RESTful Authentication plug-in on my rails application.

There is a typical scenario when a user stays at login screen for enough time (let's say 1 day..) that makes the authentication token invalid due to time expire.

When this user tries the next day to login (he didn't refresh, he is still with this invalid token), he will get an "500" http error. Making the application crash for that request.

I'm wondering if it's possible to catch this expection and warn the user. Like any other innocent web user he just does back and tries again.. and again gets the same error...

like image 624
Pedro Cunha Avatar asked Dec 30 '09 16:12

Pedro Cunha


1 Answers

In your application_controller.rb you'll do something like:

rescue_from Your::Exception, :with => :show_some_error_page

This will let you show some action, in this case show_some_error_page when an unhandled exception occurs.

I hope this helps.

like image 156
jonnii Avatar answered Nov 10 '22 05:11

jonnii