Skip to content

Instantly share code, notes, and snippets.

@senhorinha
Created June 19, 2016 13:27
Show Gist options
  • Save senhorinha/836653c6e72794f4000ba6cefebb925a to your computer and use it in GitHub Desktop.
Save senhorinha/836653c6e72794f4000ba6cefebb925a to your computer and use it in GitHub Desktop.
O que tu prefere
def register_owner
uuid = qr_code_params[:uuid]
qr_code = QrCode.find_by(uuid: uuid)
if(qr_code)
if(qr_code.user)
render json: QrCodeAlreadyHasAnOwnerError.new(uuid), status: :conflict
else
@current_user.qr_codes << qr_code
render json: qr_code, status: :created
end
else
render json: QrCodeNotFoundError.new(uuid), status: :not_found
end
end
def register_owner
uuid = qr_code_params[:uuid]
qr_code = QrCode.find_by(uuid: uuid)
return json: QrCodeNotFoundError.new(uuid), status: :not_found unless qr_code
return json: QrCodeAlreadyHasAnOwnerError.new(uuid), status: :conflict unless qr_code.user
@current_user.qr_codes << qr_code
render json: qr_code, status: :created
end
@CarlosBonetti
Copy link

👇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment