Skip to content

Instantly share code, notes, and snippets.

@sprite2005
Created April 13, 2009 22:43
Show Gist options
  • Save sprite2005/94801 to your computer and use it in GitHub Desktop.
Save sprite2005/94801 to your computer and use it in GitHub Desktop.
class ApplicationController < ActionController::Base
rescue_from ActionController::InvalidAuthenticityToken, :with => :bad_token
def bad_token
flash[:notice] = "Your session has expired."
respond_to do |accepts|
accepts.html do
store_location
redirect_to(:controller => '/sessions', :action => 'new') and return false
end
accepts.xml do
headers["Status"] = "Unauthorized"
headers["WWW-Authenticate"] = %(Basic realm="Web Password")
render :text => "Could't authenticate you", :status => '401 Unauthorized'
end
accepts.js do
store_location
render :update do |page|
page.redirect_to(:controller => '/sessions', :action => 'new') and return false
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment