Skip to content

Instantly share code, notes, and snippets.

@momolog
Created March 29, 2012 10:07
Show Gist options
  • Save momolog/2235614 to your computer and use it in GitHub Desktop.
Save momolog/2235614 to your computer and use it in GitHub Desktop.
"valid" action - throw-catch
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