Created
March 29, 2012 10:07
-
-
Save momolog/2235614 to your computer and use it in GitHub Desktop.
"valid" action - throw-catch
This file contains 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
def valid | |
failure = catch :fail do | |
code = Code.find_by_value(params[:id]) or throw(:fail, 'unknown') | |
code.unused? or throw(:fail, 'used') | |
nil | |
end | |
respond_with({:valid => !failure}.merge(failure ? {:reason => failure}: {})) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment