Created
January 5, 2009 15:24
-
-
Save oleganza/43430 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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