Skip to content

Instantly share code, notes, and snippets.

@oleganza
Created January 5, 2009 15:24
Show Gist options
  • Save oleganza/43430 to your computer and use it in GitHub Desktop.
Save oleganza/43430 to your computer and use it in GitHub Desktop.
# BEFORE
def access_denied!
throw(:halt, :access_denied)
end
def access_denied(message = "Please sign in first")
case content_type
when :html
store_location
redirect url(:signin_or_signup), :message => {:error => message}
when :xml
# FIXME: throws :halt again (access_denied is already in the try/catch block!)
# TODO: need refactoring
basic_authentication.request
when :json
display({:error => message})
end
end
# AFTER
def access_denied!
case content_type
when :xml
basic_authentication.request # this throws :halt, so we don't put it into #access_denied
else
throw(:halt, :access_denied)
end
end
def access_denied(message = "Please sign in first")
case content_type
when :html
store_location
redirect url(:signin_or_signup), :message => {:error => message}
when :json
display({:error => message})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment