Skip to content

Instantly share code, notes, and snippets.

@ept
Created August 4, 2011 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ept/1124644 to your computer and use it in GitHub Desktop.
Save ept/1124644 to your computer and use it in GitHub Desktop.
class BridgeController < ApplicationController
rescue_from YouShallNotPassException, :status => 403, :error_code => 'no_way' do |exception, response|
response[:where] = exception.backtrace.first
end
# Assuming a route like this:
# map.connect "/khazad_dum/bridge/cross", :controller => :bridge, :action => :cross, :format => :json
# then this will return a HTTP 403 error with the following JSON object as body:
# {"error_code": "no_way", "message": "No balrogs past this point please",
# "where": "bridge_controller.rb:12:in `cross'"}
def cross
raise YouShallNotPassException, "No balrogs past this point please" if current_user.is_a?(Balrog)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment